I have a code where I am inserting a new record into a database. I need a way of redirecting the user if they have already entered their information into the database. Here is my php code...how would I modify this to check for an existing record based on their entered username/email??


<? $passwordretype=$_POST['passwordretype']; $Username=$_POST['email']; $Password=$_POST['password']; mysql_connect("localhost", "xxxxxx", "tytytyty") or die(mysql_error()); mysql_select_db("xxxxxx") or die(mysql_error()); mysql_query("INSERT INTO `xxxx` VALUES ('$Username', '$Password' )"); ?>

also I need a way to check if the $passwordretype = the $Password.

are there any simple fixes???

Member Avatar

Password is easy:

if($password == $passwordretype){
   //carry on
   //an error

DO a select query on the DB against the username or email.

SELECT ... FROM users WHERE username = '$user' OR email = '$email' 

If they match - i.e. a record is returned:

  //ok do redirect, e.g. header('Location: mistake.php');
  //add data to DB