0

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???

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
1

Password is easy:

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

Redirect:
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:

if(mysql_num_rows($result)){
  //ok do redirect, e.g. header('Location: mistake.php');
}else{
  //add data to DB
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.