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 3 of 3

Thread: query

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    query

    I want to check if an item is already in the database and have an if statement.
    I am trying

    PHP Code:
    if(@mysql_fetch_array($result1)!= null)
      {
    ...
      } 
    I know this is wrong.But not sure what it should be

    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    PHP Code:
    $query "SELECT count(*) FROM table1 WHERE field1 = 'whatever it is that identifies the item uniquely'";
    $result mysql_query($query);
    if (!
    $result) {
        die(
    "SQL error: ".mysql_error());
    }
    if (
    mysql_result($result0) == 1) {
        echo 
    "Row already in table";
    } else {
        echo 
    "Row not in table";


  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks!


  •  

    Posting Permissions

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