Natt Posted October 10, 2012 Share Posted October 10, 2012 Hi I am unable to access the 'sitename' database (and the corresponding 'users' table) that we are using for the hands-on tutorial for the book. I had been working through the book until the end of Chapter 8, script 8.7, the password module. Here is the error that I get: Warning: require_once(mysql_connect.php): failed to open stream: No such file or directory in C:\xampp\htdocs\password.php on line 10 Fatal error: require_once(): Failed opening required 'mysql_connect.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\password.php on line 10 Since I couldn't change any password successfully, I tried to access the database directly from the phpadmin panel to view the records. However, I am not able to question the database directly like I used to before. I am not sure what happened. On the left panel, if I select recent tables, in the drop down list I can see 'sitename','users' but if I select it, everything reverts back to select tables. One other thing, on the phpadmin, when I check the status of the server, I get the message: This MySQL server has been running for 4 days, 22 hours, 38 minutes and 13 seconds. It started up on Oct 05, 2012 at 06:55 AM. Nb. that my view users module (Script 8.4) seem to work very well. Has anyone experienced this problem before? Natt Link to comment Share on other sites More sharing options...
rob Posted October 10, 2012 Share Posted October 10, 2012 Read the error message, the Fatal error you're getting is not a database error. Show the code for the require_once( ) statement in password.php Where is the mysql_script.php script relative to password.php? 1 Link to comment Share on other sites More sharing options...
Natt Posted October 10, 2012 Author Share Posted October 10, 2012 Good evening; I have just been checking everything - my folder was disorganized. After organizing everything once again, (in the 'change password' menu) it recalls the entry form without a problem. However, I cant update the changes, even though I can see the records in view users. I get the error(s) - in red writing: The email address and password do not match those on the file. (apparently from line 81 in the code) I just cant seem to get to the stage where it updates the new password i.e. it isn't going into the IF statement on line 43 (And I don't know how I can display/test the content of IF (empty(errors)) on line 43. Please help. You maybe able to see something that I am not seeing. <?php # Script 8.7 - password.php #2 // This page lets a user change their password: $page_title = 'Change Your Password'; include('includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { require_once ('../../mysqli_connect.php'); // Connect to the db. $errors = array(); //Initialize an error array. // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email adress.'; } else { $e = mysqli_real_escape_string($dbc, trim(stripslashes($_POST['email']))); } // Check for the current password: if (empty($_POST['pass'])) { $errors[] = 'You forgot to enter your password.'; } else { $p = mysqli_real_escape_string($dbc, trim(stripslashes($_POST['pass1']))); } // Check for a password and a match // against the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'You new password did not match the confirmed password.'; } else { $np = mysqli_real_escape_string($dbc, trim(stripslashes($_POST['pass1']))); } } else { $errors[] = 'You forgot to enter your new password.'; } echo $e; // Testing variables echo $p; // Testing variables echo $np; // Testing variables if (empty($errors)) { // Everything is OK. // Check that they have entered the right email address/password combination: $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) { // Match was made. //Get the user ID: $row = msqli_fetch_array($r, MYSQLI_NUM); // Make the update query: $q = "UPDATE users 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 '<h1>Thank you!</h1> <p>Your password has been updated. In chapter 11 you will actually be able to log in!</p><p></P>'; } else { // If it did not run OK // Print a message: echo '<h1>System Error</h1> <p class="error">Your password could not be changed due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // Include the footer and quit the script (to not show the form). include(includes/footer.html); exit(); } else { // Invalid email address/password combination. echo '<h1>Error!</h1> <p class="error">The email address and password do not match those on the file.</p>'; } } else { // Report the errors. 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($errors)) IF. mysqli_close($dbc); // Close the database connection. } // End of the main Submit conditional. ?> <h1>Change Your Password</h1> <form action="password.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></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 Password: <input type="password" name="pass2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="register" maxlength="20" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php ?> Link to comment Share on other sites More sharing options...
Recommended Posts