Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with PHP/MySQL code

    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";
    exit;
    }
    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.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •