Jump to content
Larry Ullman's Book Forums

All Activity

This stream auto-updates     

  1. Last week
  2. Thanks for the nice words! This is really strange. According to the PHP manual: I looked around and don't see any obvious causes and solutions to this, not even specific to Wampserver. Just to be certain, are you running the script through HTTP?
  3. Thanks! I don't have plans to update the PHP Advanced book right now, which means it wouldn't be updated for quite a while. But, yes, PHP does support using object-oriented and procedural programming intermixed.
  4. Hey Jim, Thanks for the nice words! I really appreciate it. There was an error in the SQL file (from my GitHub downloads) that set the length as too short. Did you use that? Or, put another way, what's the length of the password column you're using?
  5. Hi ProgMan, can you post your code so a least we can see on your end if you doing something wrong. And did you check the WAMPSERVER is running correctly when testing your code.
  6. The @ is the error suppression operator. It's a blunt tool to stop errors from being displayed, but you'll generally only want to use it when the errors are still being handled in some way.
  7. If developing locally, what you really want to do is enable display_errors in your PHP configuration. If not developing locally, you'll want to do this too, but it may not be as easy! Otherwise, you'll need to find out where your web server records error messages (what log file) and then open that to see what the problem is.
  8. D'oh! Thanks for pointing that out.l I'll get it fixed!
  9. My code is as follows: <?php # Script 10.3 - edit_user.php // This page is for editing a user record. // This page is accessed through view_users.php. $page_title='Edit a User'; include('includes/header.html'); echo'<h1>Edit a User</h1>'; // Check for a valid user ID, through GET or POST: if((isset($_GET['id'])) && (is_numeric($_GET['id']))) { // From view_users.php $id = $_GET['id']; } elseif((isset($_POST['id'])) && (is_numeric($_POST['id']))) { // Form submission. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<p class="error">This page has been accessed in error.</p>'; include('includes/footer.html'); exit(); } require('../mysqli_connect.php'); // Check if the form has been submitted: if($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = []; // Check for a first name: if(empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = mysqli_real_escape_string($dbc, trim($_POST['first_name'])); } // Check for a last name: if(empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = mysqli_real_escape_string($dbc, trim($_POST['last_name'])); } // Check for an email address: if(empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e=mysqli_real_escape_string($dbc, trim($_POST['email'])); } if(empty($errors)) { // If everything's OK. // Test for unique email address: $q = "SELECT user_id FROM users WHERE email='$e' AND user_id != $id"; $r = @mysqli_query($dbc, $q); if(mysqli_num_rows($r) == 0) { // 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>'; } // End of if (empty($errors)) IF. } // End of submit conditional. // Always show the form.... // Retrieve the user's information: $q = "SELECT first_name, last_name, email FROM users WHERE user_id=$id"; $r = @mysqli_query($dbc, $q); if(mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the usre's information: $row = mysqli_fetch_array($r, MYSQLI_NUM); // Create the form: echo'<form action="edit_user.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15 maxlength="15" value="'.$row[0].'"></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="'.$row[1].'"></p> <p>Email Address: <input type="email" name="email" size="20" maxlength="60" value"'.$row[2].'"></p> <p><input type="submit" name="submit" value="Submit"></p> <input type="hidden" name="id" value="'.$id.'"> </form>'; } else { // Not a valid user ID. echo '<p class="error">This page has been accessed in error</p>'; } mysqli_close($dbc); include('includes/footer.html'); ?>
  10. Larry, Is there an easy way to debug when you get a Server Error? I've proofread multiple times, and can't seem to find my typo, I'm sure there is some simple miss I'm not catching I'm using the 5th Edition of PHP and MySQL for Dynamic web sites, and I'm working on the edit_user.php in Chapter 10 I have been successful in getting the view_users.php to work along with the delete_user.php Thanks Tony
  11. Page 72, it says equal to 2021 but in the code is <= 2027. 😉
  12. Earlier
  13. Hi Larry As a newbie to php and web development (I am a bit 'old school' coming from a desktop/Windows background) and I am working through Edition 5 of your excellent book and have hit an early snag.... I am running everything locally on my laptop using Wampserver 3.1.3 which I believe is configured correctly as it runs other code successfully and pushes it out to IE and Chrome without any problem. Chapter 1 contains the $_SERVER variable exercise which, on the face of it shouldn't pose any issues - but I am struggling to understand what is going on with my particular set up. Basically, I am getting a null return from all the 3 server variable that you list in the exercise (the code initially failed with an invalid index error that I was able to resolve with the isset() function). When I do a phpinfo() check from within a php code snippet it suggests that these variables are not available (and all _SERVER variables are missing the leading $), whereas if I run phpinfo() directly from the link on the Wampserver homepage a much more comprehensive list of variables is displayed. Whilst this issue is clearly not a showstopper it highlights a fundamental learning issue that I need to understand if I am to code with confidence in php. Can you help please? Many thanks
  14. Hi Jim, I'm not sure what technique you are using but since PHP 5.5+ there are PHP functions 'password_hash' to create a very strongly hashed password and 'password_verify' to check them. You can see these if you Google for them. I discussed this briefly with Larry a little while ago and he suggested using these. Hope it helps. Cheers
  15. I'm comparing the two Scripts 12.1 and 12.2 and notice line 12 if ($dbc = mysqli_connect('localhost', 'username', 'password', 'myblog')) { // Script 12.1 if ($dbc = @mysqli_connect('localhost', 'username', 'password', 'myblog')) { // Script 12.2 What is the use of the '@'? What is the difference between with and without '@' on @mysqli_connect() and when to use the '@'?
  16. Greetings! I'm so stuck and perhaps you can help me.. (BTW, I'm using the most current versions of PHP 7.2.1) and MYSQL... Everything has been working great going through the lessons, however, once I get to the "Securing Passwords with PHP" portion I'm not getting the results that are expected in the chapter.. 1) I've updated "site name" database as per the requirements (ALTER TABLE users MODIFY COLUMN) and wiping out passwords (UPDATE users SET pass = ' ';) 2) I've updated the "register.php" old 9.5 script to reflect the new 13.7 script; even going as far as copying/pasting and validating it was a match.. ensuring that the new changes/lines were there.. 3) When I register a new user, it works; it's even showing in my database... 4) I've updated 'login_functions.inc.php to 13.8 script. Now here is the issue: - I can't log in as it's showing: Error! The following error(s) occurred: - The email address and password entered do not match those on file. Please try again. I can't figure out why this is happening; I see my new registration in the DB but I can't log in. I'm not sure what other information I need to provide, but that's what I have right now.. Please help - I've walked away from it several times, even going all the way back to Chapter 12 and starting over to see if I've missed anything.. Thanks in advance.. I LOVE your book! this is the second edition I've bought! I love the latest! Jim Hipolito
  17. Hi,Larry PHP and MySQL for Dynamic Web Sites:Visual QuickPro Guide(4th Edition)is a process-oriented,PHP Advanced and Object-Oriented Programming:Visual QuickPro Guide(3rd Edition)is object-oriented,is programming oriented already mainstream programming? Can it be mixed with object-oriented? Do you have plans to update the contents of the object-oriented book? Thank you.
  18. Hi Larry, Thanks for your thoughts (as always:-) I have tested my routine above in tables with and without foreign key (FK) constraints and it works OK. But I found a way to check if a table has FK constraints (with thanks to stack exchange); SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = 'database name' and REFERENCED_TABLE_NAME = 'table name'; You can leave the table name off it you don't know if any tables have FK constraints, then in the returned data, look for non-NULL data elements for REFERENCED_COLUMN_NAME and REFERENCED_TABLE_NAME. Cheers
  19. John55

    2Nd Edition To Be Completed?

    I am 63 years old, sure would like to see this completed in my lifetime. It is an excellent book so far
  20. Thanks for the nice words. Very much appreciated! Can you clarify: are you having problems with the sandbox usage of PayPal or the production usage?
  21. You can swap !empty() for empty() if you're more comfortable with that logic, but you'd have to rework all the other logic, too. For example, your code checks if the password matches the confirmed password if the password is empty. It also sets $problem equal to true if the password is not empty. Both of these are backwards. If you want to use empty(), rework the following subsections, too.
  22. Apologies for the delayed reply; I was on vacation! Kudos for figuring it out, though, and thanks for posting your solution!
  23. Apologies for the delayed reply; I was on vacation! Thanks for your question and interest in the book. The fourth edition was a really heavy rewrite of the 3rd edition; the fifth edition is a fairly mild update: Fixed all the bugs; made everything up-to-date for the current standards, PHP 7, etc.; moved the appendix back into the printed edition, but lost Chapter 19 accordingly; added a bit more security. It covers the same OOP as the 4th and I'm pretty sure both cover PDO for MySQL. If you have the 4th edition, you may not benefit that much from the 5th (maybe look at "What's new in PHP 7" instead). Thanks again!
  24. Thomas

    Chapter 6 Ipn

    Hi: I got the same error, but the solution that worked for you is not working anymore because Paypal has phased out HTTP/1.0 . So I am getting no response with the solution you have provided. Paypal now a completely different script which is very different from the one used in your example. I have tried everything but its not working. Could someone please update the ipn script (the ipn_log.php file) in the example so that the example is still usable. Thanks Thomas
  25. Hi Larry: I am using your book "Effortless E-commerce with php and mysql 2nd edition" to create a subscription website. When using your example 1 scripts, everything worked fine except that the database was not updating. The log was showing a 400 - Bad request error.The reason I found in one of your forums was a change in paypal's IPN script requirements, however the solution mentioned there is no more valid as paypal has made further changes to the scripts. It is now a completely different script which is very different from the one used in your example. I have tried everything but its not working. Could you please update the ipn script (the ipn_log.php file) in your example so that your example is still usable. Also would it be possible for you to send me a copy of the updated script by e-mail or a link to the updated script. I like all your books and commend you on your presentation style, especially the fact that you make extremely complicated things so simple. Thanks, and waiting for your reply Thomas
  26. Hi! It is now solved! Actually I had deleted XAMPP and reinstalled it because of some Mysql problems. Then I forgot that the database were all affected. As a solution I had to create all the databases again. Thanks a lot. Tri.
  1. Load more activity
×