finding duplicate value in table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jpn
Forum Newbie
Posts: 1
Joined: Sat Aug 20, 2005 8:12 am

finding duplicate value in table

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Moved to PHP-Code.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
}
Post Reply