ibuprofen Posted August 10, 2010 Share Posted August 10, 2010 The code below is a function that checks to see if an email address exists in a database, if so it alerts the user. The db has one table and one field. It works fine when there is ONE record! However, if there are > 1 it doesn't work. How can I step through each record and compare it to what the user entered? Of course, $_POST is the user's value and the db record is the $myAddy value. <?php function emailLookup() { include ('file:///Library/WebServer/Documents/re_connect_scripts/emailLookup.php'); while ($row = mysqli_fetch_array($result)) { extract ($row); $myAddy = $addy; } if ($_POST["add_email"] == $myAddy) { global $lookupError; $lookupError = 'This email address is already on the list.'; global $counter; $counter++; } else { return; } } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 10, 2010 Share Posted August 10, 2010 If all you need to do is see if the address exists in the table or not, a simple SELECT COUNT() query would be more than adequate. Quote Link to comment Share on other sites More sharing options...
sinista Posted August 10, 2010 Share Posted August 10, 2010 your searching for the number of times there is a mail address in the DB? <?php function fetchNum($sql){ $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows < 1){ $result = 0; } else { $result = $num_rows; } return $result; } $sql = "select * from tablename where fieldname ='".$_POST['REQUEST VAR']."' "; if(fetchNum($sql) >= 1)) { echo "exists"; } else { echo "doest exist"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.