The code below is supposed to check whether the name already exists in the database, and if it is already there then set a boolean. But it does set the boolean even if the name does not exist; I’ve verified this many times. So I think it must be my code that’s wrong. I understand the line below as a check to see
if ($row = mysql_fetch_assoc($result))
I think this line is checking whether there was result found at all. If a result is found then the conditional evaluates to TRUE, so $row gets assigned. Is that correct?
Do you see any other problems with the code or something that is done badly? I’m suspicious of the line that contains the mysql_query since sometimes, when you search for a name that’s not in the table of the database, it still enters the if block.
$udid_mismatch = false;
$name_found = false;
$result = mysql_query("SELECT udid
FROM $table
WHERE name='$name'");
if($row = mysql_fetch_assoc($result)) {
$name_found = true;
if($row['udid'] != $udid) {
$udid_mismatch = true;
}
}
1 Answer