Jump to content
Larry Ullman's Book Forums

phpstuff

Members
  • Posts

    107
  • Joined

  • Last visited

Everything posted by phpstuff

  1. Under "To begin a Session" it states that: "Since there are no echo statements, inclusions of HTML files, or even blank spaces prior to this point in the script, it will be safe to use session_start() at this point..." My confusion is that there are spaces prior to using the session_start(). Can you maybe define the type of space? Do these spaces not matter? I'd just like to get this straight in my head. Thanks!
  2. I did edit the php.ini file within MAMP, however, I discovered that there are 2 locations where different php.ini files are located!!! I just actually did some additional research and people were having the same issue as me: From: http://stackoverflow.com/questions/14581460/mamp-really-wont-display-errors "MAMP was reading from /MAMP/bin/php/5.4.4, I was editing /MAMP/conf/php/5.4.4. What a pain!" And I completely agree with their last statement! Hope this helps somebody else... (Make sure to edit the file associated with the version of PHP you are running. I'm running PHP5.4.10 and when I edited that it finally worked). Make sure to also stop the servers that are running in MAMP, and then restart them. Once I did this, it worked: Warning: require(../mysqli_connect.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/PHP_MYSQL/login.php on line 14 Fatal error: require(): Failed opening required '../mysqli_connect.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php') in /Applications/MAMP/htdocs/PHP_MYSQL/login.php on line 14 I've never been so happy to see error messages.
  3. Getting blank screen - I went back into the php.ini file (see below) to double check it. I set the following and removed the ";" so that they aren't commented out: display_startup_errors = On display_errors = On error_reporting = E_ALL Isn't this all I really have to do? What else could be the problem here? I did read somewhere that you have to restart the servers for changes to take effect - I did that twice already... Any other ideas? **BELOW = The entire Error handling section excerpted from my php.ini file. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Error handling and logging ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; error_reporting is a bit-field. Or each number up to get desired error ; reporting level ; E_ALL - All errors and warnings ; E_ERROR - fatal run-time errors ; E_WARNING - run-time warnings (non-fatal errors) ; E_PARSE - compile-time parse errors ; E_NOTICE - run-time notices (these are warnings which often result ; from a bug in your code, but it's possible that it was ; intentional (e.g., using an uninitialized variable and ; relying on the fact it's automatically initialized to an ; empty string) ; E_CORE_ERROR - fatal errors that occur during PHP's initial startup ; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's ; initial startup ; E_COMPILE_ERROR - fatal compile-time errors ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) ; E_USER_ERROR - user-generated error message ; E_USER_WARNING - user-generated warning message ; E_USER_NOTICE - user-generated notice message ; ; Examples: ; ; - Show all errors, except for notices ; ;error_reporting = E_ALL & ~E_NOTICE ; ; - Show only errors ; ;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; ; - Show all errors except for notices ; error_reporting = E_ALL ; Print out errors (as a part of the output). For production web sites, ; you're strongly encouraged to turn this feature off, and use error logging ; instead (see below). Keeping display_errors enabled on a production web site ; may reveal security information to end users, such as file paths on your Web ; server, your database schema or other information. ;display_errors = Off <==Original line here, below I changed it to turn on display errors display_errors = On ; Even when display_errors is on, errors that occur during PHP's startup ; sequence are not displayed. It's strongly recommended to keep ; display_startup_errors off, except for when debugging. display_startup_errors = On ; Log errors into a log file (server-specific log, stderr, or error_log (below)) ; As stated above, you're strongly advised to use error logging in place of ; error displaying on production web sites. log_errors = On ; Set maximum length of log_errors. In error_log information about the source is ; added. The default is 1024 and 0 allows to not apply any maximum length at all. log_errors_max_len = 1024 ; Do not log repeated messages. Repeated errors must occur in same file on same ; line until ignore_repeated_source is set true. ignore_repeated_errors = Off ; Ignore source of message when ignoring repeated messages. When this setting ; is On you will not log errors with repeated messages from different files or ; sourcelines. ignore_repeated_source = Off ; If this parameter is set to Off, then memory leaks will not be shown (on ; stdout or in the log). This has only effect in a debug compile, and if ; error reporting includes E_WARNING in the allowed list report_memleaks = On ; Store the last error/warning message in $php_errormsg (boolean). track_errors = Off ; Disable the inclusion of HTML tags in error messages. ;html_errors = Off ; If html_errors is set On PHP produces clickable error messages that direct ; to a page describing the error or function causing the error in detail. ; You can download a copy of the PHP manual from http://www.php.net/docs.php ; and change docref_root to the base URL of your local copy including the ; leading '/'. You must also specify the file extension being used including ; the dot. ;docref_root = "/phpmanual/" ;docref_ext = .html ; String to output before an error message. ;error_prepend_string = "<font color=ff0000>" ; String to output after an error message. ;error_append_string = "</font>" ; Log errors to specified file. error_log = "/Applications/MAMP/logs/php_error.log" ; Log errors to syslog (Event Log on NT, not valid in Windows 95). ;error_log = syslog
  4. Cool thank you...yes I need to probably learn how to use my text editor better but all my time is taken up trying to cram PHP into my head! Once I get through this book that is on the to do list.
  5. Perfect. Thank you for clearing that up. That does make sense and gives me a good starting point to research further. Thanks!
  6. As far as bugs go, It seems on every script the main issues I have had on the first book and up to Ch 12 on this book are usually mismatched/missing/too many brackets and parenthesis: ( ) { } [ ] One thing that I have just started doing that I probably should have started doing a while ago is using Command-F to perform a search of the code. Once you pull up the find window, you can count the symbols - for example count the parethesis that opens to the right. Say that count is 7. Next search for all the parenthesis that open to the left. If that count is equal to 7 then you have matching parenthesis within your code, if it is not, then you need to make them match. Repeat the process for the primary types of symbols found in your code. This has saved me some time and I'm guessing a lot of people do this, but I just figured this out.
  7. For example, if you insert files into a DB and the files have the same name, would it not matter because the index is unique? Say there are no records in the database and only Row 1 has a file uploaded: Row 1 data_id photo_of_the_desert.jpg Then somebody else (or that same person) adds another photo and it just so happens to have that same exact file name: Row 2 data_id photo_of_the_desert.jpg I'm assuming each row would have its own unique identifier (data_id might increase incrementally/change for each uploaded file?). I was more or less just curious how uploading files to folders compares to using a DB for storage - advantages, disadvantages, and when you should use one or the other.
  8. On pg 347 in the 4th TIPS from the top it is mentioned that the move_uploaded_file function will overwrite an existing file with the same name. Questions: 1. How does this work with uploading to folders VS. uploading to database? 2. In a database would it not matter as long as it is a single file being added to a unique user_id? 3. What would you do if there are multiple files and you want to prevent this from happening in a database? In a folder? I'm guessing that you somehow concatenate a random # to the filename? Not sure but I'd sure love to have more insight here as this is something that I plan on implementing in future sites (user can upload 10 photos to a single page, etc). Thanks!
  9. Select a JPEG or PNG image to be uploaded: File: (browse) The above is what my browser displays, and it does work properly, however, there is no text box between the "File:" and the "Browse" button. Is this normal, or should there be one there?
  10. The code print out on pg 324 does not have the "updated code" highlighted for pg 326 (step 5) indicating that a change will need to be made (over the previous version of the script 10.4). If you are just following the highlighted code and not reading each step in the chapter, the script won't work because you will have missed changing the table headers from non-linked text to links for sorting the records. The code listed on page 324 is correct, however, its just not highlighted which makes it look like a change wasn't required there.
  11. Arrgh... Once again I missed an underscore, a semicolon, and a parenthesis!! I was still getting a blank screen even though I had display_errors = On. Any idea why?
  12. Thanks Larry, historically I've always worked through the error but I can see as code gets longer this will become a requirement... I added: ini_set ('display_errors', 1); // TURN ON DISPLAY ERRORS And I also went into the php.ini file and changed it to: display_errors = On I am still getting a blank screen... I thought maybe having both on caused the issue - so I deleted the ini_set line from the code - still get a blank page. Any ideas?
  13. Been over this multiple times, found some errors and fixed them and went through 2 more times but still can't see what is wrong here: <?php # Script 10.4 - view_users.php #4 // This script runs a query on the username database, and retrieves all the records from the users table $page_title = 'View the current users'; include ('includes/header.html'); echo '<h1>Registered Users</h1>'; require ('mysqli_connect.php'); // Connect to the database // 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 determine // Count the number of records $q = "SELECT COUNT(user_id) FROM users"; $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 (dr = date registered) $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER BY registration_date 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 (It's set above to #eeeeee, this test with Ternary Operator will be true right now only if the color is #eeeeee, and since its currently set to #eeeeee above, it will be true (#eeeeee == #eeeeee) so the color returned will be #ffffff. Next time through the loop, the color will be what it was just set to #ffffff, so when it does a test, it will be false, which will return the second color (#eeeeee). This process will repeat itself which will create candy striping in the table rows. 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>'; // Close the table mysqli_free_result ($r); // Free up the memory resources (an optional step that is considered good form) mysqli_close($dbc); // Close the database connection // 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 $current_page = ($start/$display) + 1; // If its 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 $i . ' '; } } // End of FOR loop. // If its not the last page, make a Next button 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 ('includes/footer.html'); ?>
  14. On page 309 of the book the code is: require_once ('../mysqli_connect.php); However, in the provided downloadable script, the code is: require ('../mysqli_connect.php); Probably doesn't affect anything(?) but just throwing it out there if it could... I noticed it as I have a bug somewhere in my code and going over it again and again it stood out.
  15. Had a couple issues, was about to post here for help since I was getting frustrated and couldn't figure out, then by luck finally figured things out and thought I'd share: ISSUE #1 After filling out the registration form, I was getting an error that said: Error! The following error(s) occurred: - You forgot to enter your last name. Please try again. I made sure all fields were filled out, which they were, yet still had errors. I did "view source" on the page with the error and all the fields did have values including "last name" which was throwing an error. Turns out there was a syntax issue - instead of correct code shown below: // Check for a last name if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } I had actually typed and forgot the underscore in $_POST: // Check for a last name if (empty($POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } ISSUE #2 After I fixed the above issue, I then stopped getting that error message but then proceeded to get a blank screen (I would get the header, but nothing else after). Turns out I had the path listed wrong for the database connection script as for practice purposes I just left the script in the same folder as all the other files: Correct code (in my case since I left all files in same directory): require ('mysqli_connect.php'); // Connect to the database Incorrect code (incorrect for my case since I put this script in the same folder as all my other files, instead of doing what was recommended in the book for live sites and placing the file outside of this directory). require ('../mysqli_connect.php'); // Connect to the database After I made sure the path to the database connection script was correct, it worked finally: Thank you! You are now registered. In Chapter 12 you will actually be able to log in!
  16. Agree with above, and, to give you an idea of how long it took this newbie to get through the first book: 4 months When was the last time it took you 4 months to read 1 book right? It is normal to take a while, especially on the pages where there are 1 - 2 pages with code that you will need to type out by hand and then get stuck on and try to figure out solutions to. You aren't really "reading a book" - you are reading, trying to understand concepts, typing out code, trying to make code work, find solutions to make code work, understand why the code works, and then move on. This is a long process. Keep going and eventually the foreign language will start to become more familiar (slowly but surely like anything else in life that you practice). I just went through this, and can assure you the books are good and its worth the suffering! lol Also keep in mind that you aren't just "learning PHP." You will need to learn (not to discourage you but to explain why things don't go lightning fast) many things which I didn't realize at first being a newbie: -PHP -MySQL -SQL -How to use Terminal -How to use phpmyadmin -And probably more stuff I haven't even got to because I'm only on Ch. 10 of this book. Good luck and keep going!
  17. Also if you are 100% new to PHP, you may want to start with Larry's more beginner book "PHP for the web." I just finished that book about a month ago and am now almost to Ch 10 on this book. I'd be more lost in this book if it weren't for the first book as I was a complete newbie. Hang in there, I still am a newbie but I'm starting to slowly learn this stuff. Hope this helps... PS - don't just read the book because you won't learn much - you could read the book first then go through it and do the tutorials by hand which is what I did on the first book and I feel it helped since I was 100% new to PHP. There is a lot of help here in the forums so don't worry.
  18. Thanks for your help and suggestions above Larry! I'm glad I ran into this issue now since it forced me to go from never using terminal to starting to get a little more comfortable with it. I'll try to give back to the forums as much as I can as I really appreciate everyone's help on here. Thanks again Larry and everyone else who provides help and feedback..
  19. I had a lot of issues getting this to work, so I figured I'd try and save others the same headaches and create simple instructions on how to get this done quickly and easily. I'm using a Mac so please note in my signature to make sure what I'm running (MAMP) is the same or compatible to what you are running. 1. Open Terminal in Mac 2. Get to the root by typing: cd / 3. List all the files/folders you have in that directory by typing: ls 4. In the files/folders that appear, you should see the "usr" folder 5. Go down to the next folder called share by typing: cd share 6. Go down to the final folder called zoneinfo by typing: cd zoneinfo 7. Now take a look inside the zoneinfo folder by typing: ls 8. You should see all the system time zone info files - you will see something like: +VERSION EET Greenwich Mexico UCT Africa EST HST Mideast US America EST5EDT Hongkong NZ UTC Antarctica Egypt Iceland NZ-CHAT Universal Arctic Eire Indian Navajo W-SU Asia Etc Iran PRC WET Atlantic Europe Israel PST8PDT Zulu Australia Factory Jamaica Pacific iso3166.tab Brazil GB Japan Poland posixrules CET GB-Eire Kwajalein Portugal zone.tab CST6CDT GMT Libya ROC Canada GMT+0 MET ROK Chile GMT-0 MST Singapore Cuba GMT0 MST7MDT Turkey 9. All of this is the time zone info for areas around the world, and comes loaded with your Mac's operating system files OSX. You will notice, if you have the +VERSION file (in bold above) that it isn't a type of time zone. When you later try to run the script to take all of these time zone info files and load them into the mysql time zone tables, that terminal will catch at least that +VERSION file and say that it is "unable to load .... skipping it." I'm just showing you now what it will be referring to later on in these steps so that it is clear where everything is coming from. It may be possible that you don't have this file or any non-time zone files, in which case you may run the script and have no issues. 10. Next get back to the root by typing: cd / 11. From here you will want to navigate into the proper folder within mysql so that you can run the script from the proper location. Now jump to the applications folder by typing: cd applications 12. Jump to the MAMP folder by typing (directories are usually case sensitive so if it doesn't work check caps): cd MAMP 13. Jump to the Library folder by typing: cd Library 14. Jump to the bin folder by typing: cd bin 15. Once you are in the bin folder, you will be able to run the script. Please note that instead of jumping folders/directories one at a time that you could just instead jump directly to the final destination by typing the full path: cd applications/MAMP/Library/bin I just listed it this way for practice. 16. Now assuming you are still in the bin directory, to run the script type (or copy/paste): ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql 17. Terminal may ask you to type your password, so type it in and hit enter (as you type it, it will be invisible). 18. The result should be something like: unknown001ec2f49bea:bin matt$ ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql Enter password: Warning: Unable to load '/usr/share/zoneinfo/+VERSION' as time zone. Skipping it. 19. My terminal actually froze once it listed this as the result. The +VERSION file can't be moved into the mysql time zone table because it isn't the proper type of file. When it tries to move the file it gets hung up. So, you need to either delete the file or move the file to get it out of the way so the process can run its course. 20. To have access to actually move/delete the file, I did some research and it appears you need to give yourself single/super user mode ability (in most cases). If you do not do this, and you do not have access to move/delete files, you will see the results like I experienced below in red. Notice when you do this without the super user method terminal told me "Permission denied." You can perform the superuser method instead by typing sudo - the full command you'll need to type is below after the stuff in red. When you type "sudo" it gives you the access to do what you need to do, when you type "mv" that is the command in terminal to move a file, next is the file you want to move, and finally type the path of the destination (where you want the file to be moved to). I'm not sure how important this +VERSION file is so you can move it back after running the script if you want so that nothing is disturbed. unknown001ec2f49bea:zoneinfo matt$ mv +VERSION ~/Desktop mv: rename +VERSION to /Users/matt/Desktop/+VERSION: Permission denied unknown001ec2f49bea:zoneinfo matt$ sudo mv +VERSION ~/Desktop/ WARNING: Improper use of the sudo command could lead to data loss or the deletion of important system files. Please double-check your typing when using sudo. Type "man sudo" for more information. To proceed, enter your password, or type Ctrl-C to abort. Password: ***AT THIS POINT, ONCE I ENTERED MY PASSWORD AND HIT ENTER, THE FILE HAS BEEN MOVED TO THE DESKTOP (IT IS NO LONGER IN THE ZONEINFO FOLDER). 21. At this point, the +VERSION file is no longer in the zoneinfo folder (its on the desktop or wherever you decided to put it above), and so running the script again with the +VERSION file moved (the file causing the issue and blocking the movement of all the time zone info files to the tables) should finally work. 22. Re-run the same script as you did above, making sure to run it in the same directory/folder bin: ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql This time the results should be different since that culprit +VERSION file is gone. You will have to enter your password once again (remember as you type the password it stays invisible for security sake). See below how the script is cycling through many more files now. This should be it and everything should work at this point. I'm not sure how to confirm 100% that all the data has been populated as it should into the tables - feel free to ask some of the others on here how to do that if you feel you need to. unknown001ec2f49bea:bin matt$ ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql Enter password: Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh87' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh88' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh89' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh87' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh88' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh89' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. Hopefully this helps you out. This was a major headache and I'm glad its over!!
  20. Thanks for everyone's help here. Yeah, I think my issue was trying to determine the directory location for certain files as well - appears to be much more support for MAMP vs Xampp for Mac so for a newbie like myself when trying to google for support found little for Xampp. I was breezing along at 100 pages / week and then this loading timezones killed a week of progress...no biggie a learning experience for sure! Thanks again.
  21. After lots of headaches with Xampp for Mac, deciding to start over at Ch.5 with MAMP instead.
  22. Ok, so I ran the script slightly different with the ./ and it seemed to work (http://www.larryullman.com/forums/index.php?/topic/1072-installing-timezones-on-mysql-559-included-with-mamp-on-mac-osx-lion/). See below, but after it said "skipping it" terminal froze up. I'm going to follow a 2 yr old post on here now to remove the +VERSION (http://www.larryullman.com/2011/05/27/utc-and-time-zone-support-in-mysql/), and then go back into terminal and try running it one last time. ***Can somebody point me in the right direction as far as how to find the following directory: /usr/share/zoneinfo I can only find "share" which is found here: XAMPP / xamppfiles / share / ( there is no zoneinfo found here ) I'm beginning to think I made a very bad decision using XAMPP instead of MAMP. Can anybody chime in and let me know if I'm now at a point where I need to just start all over and begin again with MAMP? Thanks... ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql Enter password: Warning: Unable to load '/usr/share/zoneinfo/+VERSION' as time zone. Skipping it.
×
×
  • Create New...