I have the following mySQL query:
$content = mysqli_query($dblink, "SELECT * FROM passwordrecovery WHERE code = '$formcode'");
while($row = mysqli_fetch_array($content)) {
$db_username = $row['username'];
$db_email = $row['email'];
$db_code = $row['code'];
}
I would like to add an IF statement somewhere here to check whether the query is successful but I am not sure where.
Basically, I have a form where a user can insert a code (sent by email) to retrieve their password. But they might make a mistake and enter a code that doesn’t exist in the database and I would like to account for such a situation and throw back an error. I am just not sure how to do it?
On query failure,
$contentwill beFALSErather than a result resource. Check that it is not false. If they entered a non-existent code, you would get no rows back, so check for at least one row viamysqli_num_rows().We assume you have already properly escaped
$formcodeviamysqli_real_escape_string($formcode).