php - Avoiding Data Redundancy -


i working on code music site. part of registration phase. want code check database existing email addresses, if found, print " email ("email address") exists, if not found, insert information database. code seems run if email address similar 1 submitted html form found, if there no email found, system stops , nothing after that. can me figure out went wrong.

if ($_post['submit2']){  $fname = $_post['fname']; $sname = $_post['sname']; $email = $_post['emailaddress']; $pass = $_post['newpassword'];  $sql= "select * cust_information email = '$email';"; $results = mysqli_query($conn, $sql) or die(mysqli_error($conn)); $row = mysqli_fetch_array($results) or die(mysqli_error($conn));      if (count($row) < 0)     {         $sql2 = "insert cust_information (firstname, lastname, email, password) values(`$fname`, `$sname`, `$email`, `$pass`)";          $results2 = mysqli_query($conn, $sql) or die(mysqli_error($conn));          if (!$results2){          echo "successfully uploaded cust";         }        }else{          echo "email <strong>".$row["email"]. " </strong> exist";     } } 

you checking whether number of results returned less 0. length of array (and number of results found) cannot ever less 0. manual shows mysqli_fetch_array returns null if no results found, want check $row === null.

however, take opportunity point out concatenating variables sql query string leaves wide open serious security concern called sql injection. code set up, users of form able run query on database absolutely not want. recommend reading on prepared statements mitigate problem.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -