chadwick37 Posted January 13, 2012 Share Posted January 13, 2012 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 More sharing options...
Larry Posted January 13, 2012 Share Posted January 13, 2012 No, not quite. You're not looking at the right bit of code. The else clause that indicates that the email address has already been registered applies to an IF conditional that comes before what you've posted here. 1 Link to comment Share on other sites More sharing options...
Recommended Posts