Jump to content
Larry Ullman's Book Forums

hosk

Members
  • Posts

    2
  • Joined

  • Last visited

hosk's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hartley, thank you for your reply. Turns out I had left out the underscore in the $_POST argument. Thanks again!
  2. The password.php page (from Chapter 8, pg. 252, Updating records with PHP) is loading correctly in the browser, however it is not updating the database information when submitted, and does not report out any errors. I've gone line by line through the book, but I must be missing something. Any help would be most appreciated. <?php # Script 8.7 - password.php $page_title = 'Change your password'; include ('header.php'); if(isset($POST['submitted'])) { require_once ('mysqli_connect.php'); $errors = array(); if(empty($_POST['email'])) { $errors[] = 'You forgot to enter you email.'; } else { $e = mysqli_real_escape_string($dbc,trim($_POST['email'])); } if(empty($_POST['pass'])) { $errors[] = 'You forgot to enter you password.'; } else { $p = mysqli_real_escape_string($dbc,trim($_POST['pass'])); } if(!empty($_POST['pass1'])) { if($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your new password did not match the confirmed pasword.'; } else { $np = mysqli_real_escape_string($dbc, trim($_POST['pass1'])); } } else { $errors[]= 'You forgot to enter your new passsword.'; } if (empty($errors)) { $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p'))"; $r = @mysqli_query($dbc, $q); $num = @mysqli_num_rows($r); if ($num == 1) { $row = mysqli_fetch_array($r,MYSQLI_NUM); $q = "UPDATE users SET pass=SHA1('$np') WHERE user_id=$row[0]"; $r = @mysqli_query($dbc,$q); if (mysqli_affected_rows($dbc) == 1 ){ echo '<h1>Thank you!</h1><p>Your password has been updated!</p><p><br /></p>'; } else { echo '<h1>System Error!</h1><p class="error">Your password could not be changed due to system error. Ha.</p>'; echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } include ('footer.html'); exit(); } else { echo '<h1>Error!</h1><p class="error">The email address and password do not match those on file!.</p>'; } } else { echo '<h1>Error!</h1><p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { echo " - $msg <br />\n"; } echo '</p><p>Please try again. </p><p><br /></p>'; } mysqli_close($dbc); } ?> <h1>Change your password</h1> <form action="password.php" method="post"> <p>Email address:<input type="text" name="email" size="20" maxlength="80" value="" /></p> <p>Current Password: <input type="password" name="pass" size="10" maxlength="20" /></p> <p>New Password: <input type="password" name="pass1" size="10" maxlength="20" /></p> <p>Confirm New Password: <input type="password" name="pass2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Change Password" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('footer.html'); ?>
×
×
  • Create New...