Jump to content
Larry Ullman's Book Forums

Lou

Members
  • Posts

    97
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Lou

  1. Before I buy this book on Amazon (i have an earlier edition), I just have to know... Does the mod rewrite chapter detail how to change a blog post URL, from say the id and an integer, to the full name of the blog post? I would guess so, because the subtitle of the section is 'seo'. I was trying to figure out how to do such a thing on Zend Server several months ago, but moved on to a different part of my project.
  2. I'm back again with a new problem. My custom error handler works fine if there's only one error on the page, but if there's multiple errors, the first error is printed and the second error breaks the html (prints below my footer). I see what the logic error is... I'm printing my header, navigation and footer by using require_once. When there's two errors, the header, navigation and footer don't get printed but the body portion with the 2nd error does. How can I get all errors printed within the body while using my header, navigation and footer? Make the error an array? function handler($error_type, $error_message, $error_file, $error_line, $error_variables){ $message = "<p>An error of type '$error_type' has occurred in script '$error_file' on line $error_line:<br>\n"; $message .= "$error_message<br>\n"; $message .= "Date/Time: " . date('n-j-Y H:i:s') . "</p>\n"; $message .= "<pre>" . print_r($error_variables, 1) . "</pre>\n"; $messagewrapped = wordwrap($message, 75); $headers = "From: user@site.com"; if (!LIVE){ require_once(HEADER); require_once(TOPNAV); echo "<div id=\"mainfull\">\n"; echo "<h1>Error</h1>\n"; echo $messagewrapped; echo "</div>\n"; require_once(FOOTER); } else { mail(EMAIL, 'Site Error!', strip_tags($messagewrapped), $headers); require_once(HEADER); require_once(TOPNAV); echo "<div id=\"mainfull\">\n"; echo "<h1>Error</h1>\n"; $notlive = "<p>A system error has occurred. Sorry for the problem.</p>\n"; $notlive .= "<p><a href=\"index.php\">Return Home</a></p>\n</div>\n<br>\n\n"; echo $notlive; require_once(FOOTER); } } set_error_handler('handler'); I'm also having trouble catching fatal errors, it goes back to PHP's error handling, which doesn't let me use a switch statement to look for (E_ERROR). I did some reading and it seems those errors can't be caught, only user errors.
  3. This always happens. I spend a few hours trying to solve a problem, post on here, then figure it out. Why does the solution below work with OOP but not what I posted above? <?php require_once('./config.php'); $connection = new mysqli(HOST, USER, PASS, DB); if (mysqli_connect_error()){ handle_error('Message One', 'Message Two'); break; } else { return $connection; } ?>
  4. Hello again, I'm converting to mysqli OOP for connecting to my MySQL database. Previously I was using procedural mysqli. Basically, if I a connection can't be made to MYSQLI, I have a handle_error function that takes a user error message and a system error message and then uses the header redirect to my show_error page. I start the session in the config file, which is required on every page. It works when using procedural mysqli. However I can't get it to redirect using MYSQLI objects. It just shows me a white page with the system error message when it can't connect to MYSQL, like it's throwing an exception. I thought only PDO threw exceptions? I must be missing something simple, but I haven't been able to figure it out. Any help would be appreciated. <?php require_once('./config.php'); $connection = new mysqli(HOST, USER, PASS, DB); if ($connection == NULL){ handle_error('Message One', 'Message Two'); } else { return $connection; } ?> And the handle_error function in my config file: function handle_error($user_error_message, $system_error_message){ //handle all errors with this function $_SESSION['user_error_message'] = $user_error_message; $_SESSION['system_error_message'] = $system_error_message; header("Location: ./show_error.php"); }
  5. A quick followup -- Larry, you were right I could also just put my 404 page in the httpd.conf file where it mentioned ErrorDocument, not even needing an htaccess file. That "restart php" button had me stumped for weeks. I think 99% of people will think it restarts Apache.
  6. For Larry and anyone else having this problem using Zend Server, I figured it out. I tried the .htaccess method, creating a simple file within my site root, htdocs: ErrorDocument 404 /my_site/404.php It still didn't work, but I searched and found a post by someone whose htaccess file didn't have any effect. A followup post mentioned to make sure the fileinfo overide in the httpd.conf file was set to "All" and not none. I fixed this and it still didn't work. Then someone mentioned (duh) to restart Apache. I thought I was restarting Apache each time. Whenever I would make a change, I would hit the "restart PHP" button in the Zend Server GUI. However, "restart PHP" is not restarting the server (stupid, stupid on my part). So in my taskbar I just chose the icon for Apache services and hit restart. After it restarted I went to a nonexistant page and it worked, my own 404 error page. Thanks for the help and suggestions.
  7. I tried removing the hash and pointing to my 404 file but it never shows up. When I go to a page in my project that doesn't exist, it shows me a generic 'this file doesn't exist on the server' text message on a white page.
  8. There is only one httpd.conf file, can I just start a new directory tag and put the ErrorDocument directive in there? I tried to make an htaccess file once, but it didn't seem as if it was taking effect at all even after restarting the server. Here is part of the httpd.conf file, I understand what it's telling me to do, but it's not clear as to "where" I should put the ErrorDocument tag. # # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /path to file #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # # Where do I put the ErrorDocument directive with my path?
  9. I'm using Zend Server CE and I'm trying to create my own 404 error page to show when the requested page does not exist. I have asked for help on Zend's board but there doesn't seem to be many reading those boards. I have also looked up information on editing the httpd.conf and other Apache files, as well as numerous tutorials that don't seem to help since I'm using Zend Server. I can locate my httpd.conf, magic, and zend.conf files, however I don't know where exactly to add this: ErrorDocument 404 /htdocs/site im working on/404.php I don't know if Zend Server has another layer of abstraction that is making this more difficult or what, but if someone has experience creating a 404 page, especially on Zend Server Community edition, please let me know exactly what to do.
  10. The new way is just using the $_SERVER global variable instead of adding more html to the markup. There are many ways to accomplish the same task in PHP and other programming language. I originally saw this used in another text and then in Larry's E-Commerce book.
  11. Wait... there's no appendix? I can't find the book either, it's not at Barnes and Noble (in store). I'll have to order it from Amazon or Barnes.
  12. Barnes and Noble has it listed as the 23rd. I'll have to take a walk down there and read the book. I also read the first chapter on Kindle. Same book, but updated slightly (that's not a bad thing). When my financial situation turns around, I'll buy a copy. I also want to review the 2nd and 3rd editions again, which I own. Right now I'm finishing up reviewing CSS books. I'll get back to programming, I promise.
  13. Lou

    Forum Update

    How are you using IE 6? I want to try it out. Also, stop updating the forums! It seems like every month there's a new forum and all those old posts are gone. I'd still like to read my old posts back when I had no clue what was going on ("How do you code a blog?"). It's taken years of reading your books for me to reach the "mediocre level."
  14. Make sure your DOCTYPE is in caps, too. You had it in lowercase.
  15. You should download and use Netbeans, it will inform you of a missing semicolon or unmatched braces. What IDE do you use to write your code?
  16. Works fine on my end. The code you posted on the forum does not create a parse error.
  17. Did you use single quotes? Use double quotes to get the value.
  18. I think questions would be reduced if readers spent more time on the text. When I was starting, I rushed through the text and started coding right away and made some dumb, dumb mistakes. I *thought* I knew enough to start building and creating code, but clearly I didn't. For example, I started writing code on Notepad, then when there were errors, got lost trying to count the lines! I thought I'd never be a programmer.... Then I realized Notepad plus, PHPEdit, and of course Netbeans make things so much easier. And actually rereading your chapters makes thing stick much more. I always pick up something new.
  19. Larry and others... Do you get tired of answering the same questions over and over? I've been visiting this forum a lot over the past two years and have noticed the same exact questions over and over. i don't think I'd ever be a good instructor, because it drives me mad just reading the questions on here. Users don't list what version of PHP or MySQL they're using, whether or not they're using a local server or web host, and just download the code without understanding the basics and expect things to work 100%. I can't imagine what kind of web sites these people are creating...
  20. Works fine on my end. When I enter a first name, it is sticky and does not give me a warning message for the first name field.
  21. I reread this entire edition even though I own and read the 3rd edition. I really enjoyed the last two chapters, especially the quotes tutorial is very well done with lots of techniques that can be used for many other types of applications. I'm going to use this tutorial to build a nice sidebar or area that displays random items. Most boring chapter? The files chapter. If you're just going to suggest using a database, I don't see much reason to learn about file pointers and such. Maybe I shouldn't... understanding that material might fill some holes. I don't know how this edition could be better, besides using the mysqli extension instead of mysql (not that it really matters), and adding back the regular expressions chapter (with the new form of regular expressions) instead of just dropping it. Another 30-40 pages wouldn't have hurt. I'm also looking forward to reading the next edition of your PHP & MySQL book. Hopefully that update is just as good, but thanks to your books I'm starting to need more advanced material. How about an update to your Advanced PHP book?
  22. Just use the method rowCount() on your PDO statement object. Don't mix anything, you can do just about everything with PDO except multiple queries I believe, and some advanced functionality that you can use with mysqli. Here is some sample code from my PDO queries. It's for a poll. If you're interested in PDO, you should buy Murach's PHP and MySQL book by Joel Murach and Ray Harris. There is some great material on PDO and how it compares to mysqli and mysql. //define and run the query try { $success = ''; $row_count = ''; $query= "INSERT INTO mailing_list_subscribers(first_name, last_name, email) VALUES (:first_name, :last_name, :email)"; $statement=$db->prepare($query); $statement->bindValue(':first_name', $first_name); $statement->bindValue(':last_name', $last_name); $statement->bindValue(':email', $email); $success = $statement->execute(); $row_count = $statement->rowCount(); $statement->closeCursor(); } catch (PDOException $e) { $error_message = $e->getMessage(); if (!$live){ echo '<p class="error">' . $error_message . '</p>'; } else { echo '<p class="error">You were not added to our mailing list... You may have previously subscribed</p>'; } } //print a message if ($row_count == 1){ echo '<p class="success">You were added to our mailing list!</p>'; $first_name = $last_name = $email = ''; } else { echo '<p class="error">You were not added to our mailing list... You may have previously subscribed</p>'; }
  23. Code works fine for me, but get rid of the extra ">" when you thank the person by name. I don't get any errors or notices, and my error reporting is at the highest level.
×
×
  • Create New...