Registration Error php, mysql, no data in database -


this question has answer here:

i've been stuck couple days connecting registration looking through forums etc. no error seems populate on page, when take @ phpmyadmin doesn't show registration info inserted in db.

register.php

<?php  session_start();  if(isset($_session['user'])!="")  {      header("location: home.php");  } $servername = "correctly inserted info"; $username = "correctly inserted info"; $password = "correctly inserted info"; $dbname = "correctly inserted info";  $conn = new mysqli($servername, $username, $password, $dbname);    if(isset($_post['btn-signup']))  { $fname = mysql_real_escape_string($_post['fullname']);  $uname = mysql_real_escape_string($_post['username']);  $email = mysql_real_escape_string($_post['email']);  $upass = md5(mysql_real_escape_string($_post['password']));    if(mysql_query("insert users(fullname,username,email,password)  values('$fname','$uname','$email','$upass')"))   {      ?>      <script>alert('successfully registered');</script>      <?php  }  else  {      ?>      <script>alert('error while registering you...');</script>      <?php  }  }  ?> 

registration.php

<!doctype html> <!--[if ie 9 ]><html class="ie9"><![endif]--> <head>     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />     <meta name="format-detection" content="telephone=no">     <meta charset="utf-8">      <meta name="description" content="violate responsive admin template">     <meta name="keywords" content="super admin, admin, template, bootstrap">      <title>super admin responsive template</title>      <!-- css -->     <link href="css/bootstrap.min.css" rel="stylesheet">     <link href="css/form.css" rel="stylesheet">     <link href="css/style.css" rel="stylesheet">     <link href="css/animate.css" rel="stylesheet">     <link href="css/generics.css" rel="stylesheet">   </head>   <body id="skin-blur-violate">     <section id="login">         <header>             <h1>super admin</h1>             <p>lorem ipsum dolor sit amet, consectetur adipiscing elit.  nulla eu risus. curabitur commodo lorem fringilla enim feugiat commodo sed ac lacus.</p>         </header>          <div class="clearfix"></div>         <!-- login -->         <form class="box tile animated active" id="box-login">          <!-- register -->         <?php require_once("register.php"); ?>          <form class="box animated tile" id="box-register" method="post">              <h2 class="m-t-0 m-b-15">register</h2>             <input type="text" class="login-control m-b-10" placeholder="full name" name="fname" required/>             <input type="text" class="login-control m-b-10" placeholder="username" name="uname" required/>             <input type="email" class="login-control m-b-10" placeholder="email address" name="email" required/>                 <input type="password" class="login-control m-b-10" placeholder="password" name="pass" required/>              <button class="btn btn-sm m-r-5" type="submit">register</button>              <small><a class="box-switcher" data-switch="box-login"  href="">already have account?</a></small>         </form>          <!-- forgot password -->      </section>                            <!-- javascript libraries -->     <!-- jquery -->     <script src="js/jquery.min.js"></script> <!-- jquery library -->          <!-- bootstrap -->         <script src="js/bootstrap.min.js"></script>          <!--  form related -->         <script src="js/icheck.js"></script> <!-- custom checkbox +  radio -    ->          <!-- js functions -->         <script src="js/functions.js"></script>     </body> </html> 

i've editing code cause i'm still coming same issue, many seem on right track. using mysql , mysqli interchangeably. looking in dbconnect.php file , found following looks i'll need change make uniform mysqli being displayed in other areas. on right track, not there yet.

i found though dbconnect.php deploying mysql version , not mysql version thoughts?

i found though dbconnect.php deploying mysql version , not mysql version thoughts?

dbconnect.php

<?php  if(!mysql_connect("correct host","correct username","correct password"))  {  die('oops connection problem ! --> '.mysql_error());  }  if(!mysql_select_db("correct db"))  {  die('oops database selection problem ! --> '.mysql_error());  }    ?> 

based on starting responses found many we're helping me on right track...here other correlating files since general theme interchanging mysql , mysqli. parts of seemed work it's coming apart if can me put again appreciate it. i'm still having no response posting database why i'm making edits.

index.php

<?php  session_start();  include_once 'dbconnect.php';    if(isset($_session['user'])!="")  {  header("location: home.php");  }    if(isset($_post['btn-login']))  {  $email = mysql_real_escape_string($_post['email']);  $upass = mysql_real_escape_string($_post['pass']);  $res=mysql_query("select * users email='$email'");  $row=mysql_fetch_array($res);    if($row['password']==md5($upass))  {      $_session['user'] = $row['user_id'];      header("location: home.php");  }  else  {      ?>      <script>alert('wrong details');</script>      <?php  }    }  ?> 

just i'm showing have in process....i'm putting in login.php file can resolved.

login.php

<!doctype html> <!--[if ie 9 ]><html class="ie9"><![endif]--> <head>     <meta name="viewport" content="width=device-width, initial-    scale=1.0, maximum-scale=1.0" />     <meta name="format-detection" content="telephone=no">     <meta charset="utf-8">      <meta name="description" content="violate responsive admin template">     <meta name="keywords" content="super admin, admin, template, bootstrap">      <title>super admin responsive template</title>      <!-- css -->     <link href="css/bootstrap.min.css" rel="stylesheet">     <link href="css/form.css" rel="stylesheet">     <link href="css/style.css" rel="stylesheet">     <link href="css/animate.css" rel="stylesheet">     <link href="css/generics.css" rel="stylesheet">  </head> <body id="skin-blur-violate">     <section id="login">         <header>             <h1>super admin</h1>              <p>lorem ipsum dolor sit amet, consectetur adipiscing elit. nulla eu risus. curabitur commodo lorem fringilla enim feugiat commodo sed ac lacus.</p>         </header>          <div class="clearfix"></div>          <!-- login -->         <?php require_once("index.php"); ?>   <form class="box tile animated active" id="box-login">             <h2 class="m-t-0 m-b-15">login</h2>             <input type="text" class="login-control m-b-10" placeholder="username or email address">             <input type="password" class="login-control" placeholder="password">             <div class="checkbox m-b-20">                 <label>                     <input type="checkbox">                     remember me                 </label>             </div>             <button type="submit" name="btn-login" class="btn btn-sm m-r-5">sign in</button>              <small>                 <a href="registration.php">don't have account?</a> or                 <a class="box-switcher" data-switch="box-reset" href="">forgot password?</a>             </small>         </form>          <!-- forgot password -->         <form class="box animated tile" id="box-reset">             <h2 class="m-t-0 m-b-15">reset password</h2>             <p>lorem ipsum dolor sit amet, consectetur adipiscing elit. nulla eu risus. curabitur commodo lorem fringilla enim feugiat commodo sed ac lacus.</p>             <input type="email" class="login-control m-b-20" placeholder="email address">                  <button class="btn btn-sm m-r-5">reset password</button>              <small><a class="box-switcher" data-switch="box-login" href="">already have account?</a></small>         </form>     </section>                            <!-- javascript libraries -->     <!-- jquery -->     <script src="js/jquery.min.js"></script> <!-- jquery library -->      <!-- bootstrap -->     <script src="js/bootstrap.min.js"></script>      <!--  form related -->     <script src="js/icheck.js"></script> <!-- custom checkbox + radio -->      <!-- js functions -->     <script src="js/functions.js"></script>  </body> </html> 

errors

  1. you conflicting mysql , mysqli.
  2. name attribute not define on here <button class="btn btn-sm m-r-5" type="submit">register</button>
  3. in register.php check isset class, this never works if(isset($_post['btn-signup']))
  4. as form name field , retrieve fields wrong.(form - placeholder="full name" name="fname"/ in code - mysql_real_escape_string($_post['fullname']))

improvements

to check variable null or empty use empty() keyword

change this

if(isset($_session['user'])!="")  {      header("location: home.php");  } 

to this

if(!empty($_session['user'])){     header("location: home.php"); } 

bug fixed code

in register.php

if(isset($_post['register'])){      $fname = mysqli_real_escape_string($conn, $_post['fname']);     $uname = mysqli_real_escape_string($conn, $_post['uname']);     $email = mysqli_real_escape_string($conn, $_post['email']);     $upass = md5(mysqli_real_escape_string($conn, $_post['pass']));      $sql = "insert users(fullname,username,email,password)  values('$fname','$uname','$email','$upass')";      if(mysqli_query($conn, $sql))     {         ?>         <script>             alert('successfully registered');         </script>         <?php     }     else{         ?>         <script>             alert('error while registering you...');         </script>         <?php     }  } 

in registration.php

<button class="btn btn-sm m-r-5" type="submit" name="register">register</button> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -