I'd like to have a function that simply checks a variable against a db for duplicates. The problem is in the query where I have to pick the table (I think). I'm not getting it to work, and don't know where it is failing. I tried passing the name of the table as a string, and stored in a variable, and nada. This has got to be common, does anyone have any suggestions?
This is a stripped down version of the function I wrote.
Code: Select all
function chkDuplicates($tblName, $var)
{
$sql = "SELECT * FROM $tblName WHERE name = '$var'";
$result = mysql_query($sql);
$num = mysql_numrows($result);
if($num = '0')
{
return true;
}
return false;
}