Jump to content
Larry Ullman's Book Forums

ograyk

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by ograyk

  1. i have went thru this script forward and backwards a million and still have problems, i am not getting any error msgs, i am completely lost. please help. <?php # Script 10.4 - view_users.php #4 // this script retrieves all the records from the user table // the new version paginates the query results $page_title = 'View the Current Users'; include ('include/header.html'); echo '<h1>Registered Users</h1>'; require_once ('mysqli_connect.php'); // Number of records to show per page $display = 10; // determine how many pages there are if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined $pages = $_GET['p']; } else { //need to be determined //count the number records in the database $q = "SELECT COUNT(user_id) FROM users_info"; $r = @mysqli_query ($dbc, $q); // $row = @mysqli_fetch_array ($r, MYSQLI_NUM); // $records = $row[0]; // calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } // end of p IF. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } //Define the query: $q = "SELECT last_name, first_name, DATE_FORMAT(time, '%M %d, %Y') AS dr, user_id FROM users_info ORDER BY time ASC LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // // Table header: echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b>Last Name</b></td> <td align="left"><b>First Name</b></td> <td align="left"><b>Date Registered</b></td> </tr> '; // Fetch and print all the records..... $bg = '#eeeeee'; // set the initial background color while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } // End of While loop. echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc); // make the links to other pages, if necessary. if ($pages > 1) { // add some spacing and start a paragraph: echo '<br /><p>'; // Determine what page the script is on $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous link: if ($current_page != 1) { echo '<a href="view_users.php?s=' . ($start - $display) '&p=' . $pages . '">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $1 . ' '; } } // End of FOR loop. // If it's not the last page, make a Next botton: if ($current_page != $pages) { echo '<a href="view_users.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; } echo '</p>'; // close the paragraph. } // End of links section. include ('include/footer.html'); ?>
  2. I have a quick question about chapter 10, script 10.1 view_users.php; I updated the view_users.php via the script 10.1, when I executed the script, the Labels did not line up properly; Last Name, First Name, Registration Date is not in the appropriate place, they are to the far left, right below Edit. I have not made any changes to the script or to the css that I have downloaded from this site. The last view_users was visually correct and so is the home page. I am not sure why these labels are out of place and unsure of how to correct them. The books say to align to the left but I believe that is referring to inside of its header. Edit & Delete are in their respectable places. <?php # script 9.6 - view_users.php // This script retrieves all the records from the users table $page_title = 'View the Current Users'; include ('include/header.html'); // Page header echo '<h1>Registered Users<h1>'; require ('mysqli_connect.php'); // connect to database // DEFINE the query Make the query: /* original script below $q = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(time, '%M %d, %Y') AS dr FROM users_info ORDER BY time ASC"; */ // make/define the query $q = "SELECT last_name, first_name, DATE_FORMAT(time, '%M %d, %Y') AS dr, user_id FROM users_info ORDER BY time ASC"; $r = @mysqli_query ($dbc, $q); // Run the query $num = mysqli_num_rows($r); if ($num > 0) { // If it ran OK, display the records. echo "<p>There are currently $num registered users</p>\n"; // Table header echo '<table align="center" cellspacing="3" cellpadding="3" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td></tr> <td align="left"><b>Last Name</b></td></tr> <td align="left"><b>First Name</b></td></tr> <td align="left"><b>Date Registered</b></td> </tr> '; // Fetch and print all the records: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<tr> <td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } echo '</table>'; // Close the table mysqli_free_result ($r); // Free up the resources. } else { // If no records were returned // public message: echo '<p class="error">There are currently no registered users. Step yo game up!</p>'; //Debugging message: // echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // close the data connection. include ('include/footer.html'); ?> Thank you
  3. I had to go and add 'user_id' to my database, because the column was missing (smh). I was under the impression that the field was not needed because it was not coded for in the change.php script, but instead it was based off of the database design of Chapter 5. Sorry for the confusion and thanks for the help. And also thanks for the helpful problem solving tips, I know that they will be vital in the future in helping comprehend and ultimately become an overall better coder/developer. - much appreciated.
  4. My database is pretty simple, i have the database named (truce), which i have successfully connected to, and just one table within that database (users_info), which I have successfully added data. I find two discrepancies, one that I had "users_id" instead of "user_id"; I changed that. Also, I had "pass1" as a column name for password instead of "pass", which I also fixed; by changing the column in phpmyadmin to "pass" and did so accordingly with the 'register.php' script, so that they may match. I removed the error suppression and I am not recieving any new errors, only the original error message of 'The email address and the password do not match those on file. '. I double checked the variable to make sure that the variables are matching and correct, such as $e for email to make sure I did not mistakenly put a different letter or spell 'email' wrong and so on with the rest of the variable. went over your code again and it appears that the coding matches, just without the correct results. everything else seems to work properly, such as new password and confirm password not matching or missing fields.
  5. I tried that which you have instructed and still came up short; now with that being said, I am a complete novice and the error could lie there. This is my second book on php, the first one was PHP for the Web (authored by you), and am still trying to come to grips with it all. I say this in hopes that my rudiment understanding does not anger you. I watched one of your presentation on youtube and you stated to ask questions in a smart fashion and to admit when you do not know, so I hope I am covering those grounds. Now onto what is germane to my inquiry, the process I took was to code out certain scripts, such as the passwords to see if I could get it to accept and recognize the submission of the email (probably doing that wrong as well). Is there anyway that you could break it down farther? Is there anyway to tell if the problem lies within my coding itself, as if I am missing something. I looked through the forum to see if anyone else had this issue and I did not find such; so I was thinking maybe I am missing something in the book that everyone else is seeing. like I said, I have yet to break away from the book; it is my life support. All the errors that I have encountered has been because I have overlooked something. thank Larry
  6. OK, nevermind about the color thing, it appeared when I submitted my post; although I did click preview before post for this exact reason. - disregard
  7. 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'); ?>
  8. Thanx, I looked at this script numerous of times with no avail, appreciate that much.
  9. I am having trouble getting the errors to populate on my register script. I copied the code from chapter 9 explicitly and I am continuing to overlook what is causing the problem. The problem is that the correct error message does not populate, such as when there is no last name or email address, instead of expressing that, it just says that I have an error and does not say what the error is for; such as an empty field. mysql error messages work just fine. if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); //will handle/store every error msg, one for each form input improperly filled out if (empty($_POST['first_name'])) { $errors[] = 'you forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } if (empty($_POST['last_name'])) { $errors[] = 'you forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } if (empty($_POST['email'])) { $errors[] = 'you forgot to enter a email.'; } else { $e = trim($_POST['email']); } if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'your passwords do not match.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'you forgot to enter your password.'; } if (empty($errors)) { // if there are no errors // register the user in the database require ('mysqli_connect.php'); // connect to database //make the query $q = "INSERT INTO users_info (first_name, last_name, email, pass1, time) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )"; $r = @mysqli_query ($dbc, $q); // run the query if ($r) { // if everything is ok //print message: echo '<h3>Thank You!</h3> <p>you are now registered.</p> <p><br /></p>'; } else { //public msg echo '<h2>system error</h2> <p class="error"> you could not register due to system error. sorry for the inconvenience.</p>'; //debugging msg echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } //end of $r IF //close db connection mysqli_close($dbc); exit(); } else { //return error echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($error 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. }
×
×
  • Create New...