Jump to content
Larry Ullman's Book Forums

Chapter 9 - Understanding Edit A User


Recommended Posts

I am trying to understand how this script works, particularly the email conditional. Here is the code I'm trying to get my head around:

 

//Make the query:
$q = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id LIMIT 1";
$r = @mysqli_query ($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

//Print a message:
echo '<p>The user has been edited.</p>';

} else { // If it did not run OK.
echo '<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; //Public message.
echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
}

} else { // Already registered.
echo '<p class="error">The email address has already been registered.</p>';
}

} else { //Report the errors.

echo '<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
 echo " - $msg<br />\n";
 }
 echo '</p><p>Please try again.</p>';

 

What I'm not sure I understand is how the script knows to print error for a email address that has already been registered.

Is this code basically saying that if the affected rows == 0 but no errors are reported then the only other option is that you used a duplicate email address and so since there are no errors to print it echos the already registered message?

Link to comment
Share on other sites

 Share

×
×
  • Create New...