Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Record Exists (See related posts)

In mySQL (from PHP), checks for the existance of a record based on id, passing the name of the id field followed by the id to check for, the table name, and the database resource, in that order.
   1  
   2  function recordExists($id,$idval,$table,$db) {//check for id=idval in table and return TRUE or FALSE
   3     $result = mysql_query("SELECT * FROM ".$table." WHERE ".$id."='".$idval."'", $db) or die(mysql_error());
   4     if($row = mysql_fetch_array($result)) {//if we did return a record
   5        return 1;
   6     }//end if row
   7     return 0;
   8  }//end fuction recordExists

You need to create an account or log in to post comments to this site.


Click here to browse all 5349 code snippets

Related Posts