Search the Community
Showing results for tags 'not populating'.
-
I am having problems with password.php script. I believe that I have followed the book precisely, but maybe not since I am here. Nonetheless, I continue to receive an error msg after I submit the form for the new password. the msg is that - The email address and the password do not match those on file. I have double and triple, and quadruple checked to make sure that I am submitting the correct info that I registered with. My other two scripts associated with the password.php are operating properly (view_users.php & register.php); including populating the correct error msgs when forms are not correctly filled in. The only thing that I believe might be an issue outside of the script, is that it calls for an interaction with the user_id (database I'm guessing), which was not coded for per the book (I double checked a number of times). I did update the view_users.php so that it counts the number of users but I still do not see where it calls for an id in the script. And also, how do I get my script to show up as the colors of my text editor without manually changing. I use TextWrangler and have a Mac - Thanx again <?php # script 9.7 - password.php // this script allows users to change password $page_title = 'Change Your Password'; include ('include/header.html'); //check for submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { require ('mysqli_connect.php'); // connect to database $errors = array(); // initalize an error array if (empty($_POST['email'])) { $errors[] = 'you forgot to enter a email.'; } else { $e = mysqli_real_escape_string($dbc, trim($_POST['email'])); } // Check for the current password if (empty($_POST['pass'])) { $errors[] = 'you forgot to enter your current password.'; } else { $p = mysqli_real_escape_string($dbc, trim($_POST['pass'])); } // check for a new password and match against the confirmed password if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'your new password does not match your confirmed password.'; } else { $np = mysqli_real_escape_string($dbc, trim($_POST['pass1'])); } } else { $errors[] = 'you forgot to enter your a new password.'; } if (empty($errors)) { // if there are no errors // Check that they've enetered the right email address/password combination //make the query $q = "SELECT users_id FROM users_info WHERE (email='$e' AND pass=SHA1('$p') )"; $r = mysqli_query($dbc, $q); //@ $num = mysqli_num_rows($r); //@ if ($num == 1) { // match was made // get user_id $row = mysqli_fetch_array($r, MYSQLI_NUM); // make the UPDATE query $q = "UPDATE users_info SET pass=SHA1('$np') WHERE user_id=$row[0]"; $r = mysqli_query($dbc, $q); //@ if (mysqli_affected_rows($dbc) == 1) { // if it ran ok // print a message echo '<h3>Thank You!</h3> <p>Your password has been changed/updated.</p> <p><br /></p>'; } else { // if it did not run OK // public message echo '<h2>system error</h2> <p class="error"> your password could not be changed due to a system error. We apologize for any inconvenience.</p>'; //debugging msg echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } mysqli_close($dbc); // //close db connection include ('include/footer.html'); // include the footer and quit the script (to not show the form). exit(); } else { // Invalid email address/password combination - return error echo '<h1>Error!</h1> <p class="error">The email address and the password do not match those on file<p/>'; } } else { echo '<h1>Error!</h1> <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><p><br /><p>'; } // end of if (empty($error)) IF. mysqli_close($dbc); // close database connection } // end of main submit conditional. ?> <h1>Change your password</h1> <form action="password.php" method="post"> <p>Email: <input type="text" name="email" size="19" maxlength="16" placeholder="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Current Password: <input type="password" name="pass" size="15" maxlength="10" placeholder="current" value="<?php if (isset($_POST['pass'])) echo $_POST['pass']; ?>" /></p> <p>New Password: <input type="password" name="pass1" size="15" maxlength="10" placeholder="password" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>" /></p> <p>Confirm Password: <input type="password" name="pass2" size="15" maxlength="15" placeholder="re-password" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2']; ?>" /></p> <p><input type="submit" value="update/change" /></p> </form> <?php include ('include/footer.html'); ?>
- 10 replies
-
- password
- change your password
-
(and 2 more)
Tagged with: