MySQL error checking/matching

From: Date: Sun, 17 Feb 2002 06:40:07 +0000
Subject: MySQL error checking/matching
Groups: php.general 
Request: Send a blank email to php-general+get-85089@lists.php.net to get a copy of this message
Hello everyone, I have a problem. I have a test database (used to learn MySQL) with a table called customers and a field called email. The email field is set to be unique, so I know that by using: $query = "select email from customers where email = $email"; I will get one cell with the e-mail address that matches the email address specified by the variable $e-mail. Basically, I want to check to see if the e-mail address set in the variable $email matches the email address in the field named email. But I get an error at the end. Here's the source: Assumptions: - $email is set from a previous page - a database connection is open and the database to be used is selected - session settings will send $error back to the form page if result of if statement below is true $query = "select email from customers" // Check for duplicate entry . "where email = $email"; $query = stripslashes($query); $result = mysql_query($query); $num_results = mysql_num_rows($result); // Get the number of rows in database (integer) for ($i = 0; $i < $num_results; $i++) { $row = mysql_fetch_array($result); // Return results in an associative array } if($row["email"] == $email) { // Check to see if $email matches in database $error = "$email has already been registered"; header("Location: signup.php?<?=SID?>"); exit; } And this produces the following error: Warning: Supplied argument is not a valid MySQL result resource in e:\localhost/book-o-rama/admin/signup_do.php on line 34. What am I doing wrong? Any help would be appreciated...

« previous php.general (#85089) next »