MySql Check if Value Exists in Table

From: Date: Fri, 18 Aug 2000 17:49:32 +0000
Subject: MySql Check if Value Exists in Table
Groups: php.general 
Request: Send a blank email to php-general+get-12508@lists.php.net to get a copy of this message
PHPer's, Can you help me with this code? I'm trying to see if an id already exists in the table, if so give an error message. I'm getting "0 is not a MYSQL result index". function check_exists($table, $col_1, $col_2, $id_1, $id_2) { $SQL = "SELECT $col_1, $col_2"; $SQL .= " FROM $table"; $SQL .= " WHERE $col_1 = $id_1 and $col_2 = $id_2"; $result = mysql_query($SQL); echo ("Result in check_exists: $result"); if (mysql_num_rows($result) > 0) { echo ("<h3>Combination of:<br> $col_1 $id_1 and $col_2 $id_2 already exists in $table. Please reselect.</h3>"); exit; } else return -1; } Thanks, pj

« previous php.general (#12508) next »