Bateman
asked on
recordExists Function - correct use
Hi, I am starting to use a recordExists Function (shown below) to check for existing records in a database before adding a new one. Could someone help me out with the correct way in using this:
I tried the following but it didn't seem to work:
recordExists(fld_email,$em ail,tbl_us ers,$db);
if (recordExists == "1");
else
{
//stuff here
}
I tried the following but it didn't seem to work:
recordExists(fld_email,$em
if (recordExists == "1");
else
{
//stuff here
}
<?
function recordExists($id,$idval,$table,$db) {//check for id=idval in table and return TRUE or FALSE
$result = mysql_query("SELECT * FROM ".$table." WHERE ".$id."='".$idval."'", $db) or die(mysql_error());
if($row = mysql_fetch_array($result)) {//if we did return a record
return 1;
}//end if row
return 0;
}//end function recordExists
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
many thanks, seems to work!
http://se.php.net/mysql_num_rows
Open in new window