Page 1 of 1

finding duplicate value in table

Posted: Sat Aug 20, 2005 8:15 am
by jpn
Using the following code below as part of a validation script, I am trying to check that the email that is represented by $_POST['email'] has not already been entered in the table.

Code: Select all

require ('../mysql_connect.php'); // Connect to the db.
$temp = $_post['email'];    //value from form
$searchquery = "SELECT * from members where email =  '".$temp"'";
$searchresult = @mysql_query($searchquery); //run the query

if ($searchresult) {
   $num_rows = mysql_num_rows($searchresult);
      if(num_rows == 0) {      // email does not exist in table
	$e = $_POST['email'];
      }
      else {                             // email address has been found in table
	$eMess = '<p class = "bodytext">* Email address been used already!</p>' . $num_rows;
	$e = FALSE;
      }
}



However the code above is not finding the email address eben though I know it exists in the table.

Any help welcome

J

Posted: Sat Aug 20, 2005 8:25 am
by feyd
Moved to PHP-Code.

Posted: Sat Aug 20, 2005 9:23 am
by josh

Code: Select all

$result=mysql_query("SELECT COUNT(*) FROM `table` WHERE `email` = '$email' ; ");
$result=mysql_fetch_array($result);
if ($result[0]==0) {
   // doesnt exist
} else {
   // does
}