View Full Version : Need help with PHP/MySQL code

04-17-2003, 05:36 PM
I want my PHP form to be filled out, and I want certain fields to be verified against the MySQL database so that no records/rows can be duplicated upon updating the database with my form information. This is some of the code I tried so far and the only thing that seems to work is that it would verify only the first record but no others:
$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array ($result))
if (($address == $row["address"]) AND ($first_name == $row["first_name"]) AND ($last_name == $row["last_name"]))
echo "Sorry. Duplicate entry";
I assumed that I had to make it loop, but I don't even think that's necessary. I've tried mysql_fetch_object also, but to the same effect. Any help would be greatly appreciated.

04-17-2003, 05:46 PM
reverse your logic and just look for a record that meets your criterium

$quizit = mysql_query("SELECT row_id FROM `table` WHERE address='" .$_POST['address']. "' AND first_name='" .$_POST['first_name']. "' AND last_name='" .$_POST['last_name']. "'");

then if you get a row returned you know that it is a duplicate - much less query/process intense than your current method.