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 for diafol

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
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.