Jump to content
Larry Ullman's Book Forums

All Activity

This stream auto-updates     

  1. Yesterday
  2. Last week
  3. Upon re-written of the SQL below I got this error: #1067 - Invalid default value for 'date_modified' but When I removed "DEFAULT '0000-00-00 00:00:00' " the SQL ran successfully. I want to know if I am correct or not but Based on the link you sent I think I am on the way " For the first column that uses the TIMESTAMP data type in a specific table, MariaDB automatically assigns the following properties to the column: • DEFAULT CURRENT_TIMESTAMP • ON UPDATE CURRENT_TIMESTAMP. CREATE TABLE `carts` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `user_session_id` CHAR(32) NOT NULL, `product_type` enum('coffee','goodies') NOT NULL, `product_id` MEDIUMINT(8) UNSIGNED NOT NULL, `quantity` TINYINT(3) UNSIGNED NOT NULL, `date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', ` date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `product_type` (`product_type`,`product_id`), KEY `user_session_id` (`user_session_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  4. Earlier
  5. I've reviewed the MariaDB documentation for timestamp: https://mariadb.com/kb/en/timestamp/ It looks like the first timestamp column in a table has different behavior than the second. We want date_created to be automatically set on creation, but not update. We want date_modified to be automatically updated on each change. To get that behavior you'll need to change the DB and the SQL queries. Assuming we want both the date_modified and the date_created, I'd be inclined to put the date_modified column first and then populate date_created to the current timestamp upon INSERT. Or just drop the date_created column entirely and update the SQL commands accordingly.
  6. Dear all. I am having SQL issues with Table Carts and Wish_lists table on page 189, 192. the date_modified column was given error it was saying MySQL said: #1067 - Invalid default value for 'date_modified' should I just remove TIMESTAMP Data type from date_modified column and change it to DATETIME?. I am using Maria DB 10.3.15 version bundled with xampp.
  7. Unfortunately I just searched templates.com and it doesn't look like they offer it anymore. However, pages 207-210 (US English, print edition) do demonstrate the original HTML fairly well.
  8. the original template. I just want to follow everything in the book step by step as explained.
  9. Ah, okay. First, thanks for all the details. Second, I would advise against trying random things as you debug. It's a natural thing to do but tends to lead to more confusion. Here, for example, the upload script purposefully doesn't append the file extension, but that's totally okay because the show_image.php script doesn't use the file extension either. So that's actually correct and you definitely don't want to add the .jpg extension to the uploaded file (for starters, what if the upload was a PNG?). Normally if you're getting this result it's because your path to the file is incorrect. That your upload script uses ../../ch19_uploads/$id but show_image.php uses ../ch19_uploads makes me think that's the problem (assuming show_image.php and the upload script are in the same folder). Again, I definitely wouldn't move the folder, I'd just make sure you get the file path correct in the code. You can also try using an absolute path to the folder in your code.
  10. Are you talking about the original template or the code in the book?
  11. What operating system are you using? Have you tried following the book's instructions?
  12. Dear Sirs, If someone has the time, and can help me run the first program in PHP- And how to install PHP on my computer
  13. Hi sir, I could not find the coffee template that you chose for the Part three of this book before breaking them into PHP files in the code that I downloaded. pls, can we get it, I want to really follow where you got the box that you converted to Constant on page 210.
  14. Hi Greetings, Yes Sir, this is the registration script. There are two fields for the password in the registration script (1) for the password and another (2) for the confirm password. I had posted only the modified password part of the script above. Now the complete modified password part of the script is: // Check for a password and match against the confirmed password: if (preg_match('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){8,}$/', $_POST['pass1']) ) { if ($_POST['pass1'] === $_POST['pass2']) { $p = $_POST['pass1']; } else { $reg_errors['pass2'] = 'Your password did not match the confirmed password!'; } } else { $reg_errors['pass1'] = 'Please enter a valid password!'; } Many Thanks,
  15. UPDATE #2: Really trying to understand whats going on here, as I'm struggling to get the image to display for the view_print.php page. I even tried moving the ch19_uploads folder one level even deeper ( outside of the www directory itself and straight int the wamp64 directory, like I did with the folder 'uploads' in chapter 11 ) and though I can add images to this folder via add_print.php, I can't for some reason get view_print.php to display anything! The problem it seems to me, is that in the show_image.php script, where it checks that the image exists and is a file, $image is FALSE. ( the file doesnt exist or its not a file ). thats all i can think of as to why the image wont show up. How to remedy this is a brain fryer for me heh
  16. UPDATE: the reason that default image was appearing instead of the prints was because the original script in the book did not hard code any file extension for the file path and image. The default 'oops' image appears if an image does not have a .jpg file extension set. I tried to set them manually by modifying the line that renames the function like so: rename($temp, "../../ch19_uploads/$id".".jpg"); Now what im seeing is no default image appears, just the message 'no image available' is being displayed on the screen for each print. I think i'll take a break, have a coffee and return back to this. I'll re-read the entire chapter if need be, may even read the earlier chapter on header files in case I've missed something.
  17. I did try and look at the html source code using 'view source' and noticed that the ampersand '&' in the url itself was highlighted in red, not sure if thats normal or not. when viewing source code, the line which shows the url image source reads: <img src="show_image.php?image=1&name=daydreaming_by_the_river_image_copy_low_res.jpg" width="900" height="747" alt="Day dreaming by the River" /> Going into the folder where I manually saved the images from the website art2arts, ( its just a folder containing the images i select for uploading into ch19_uploads) i cross checked this image file, and sure enough its 900px (width) x 747px (height) and its called 'daydreaming_by_the_river_image_copy_low_res'. the image we are seeing appearing on the view_print.php script instead, is the oops image, interestingly its taking on the same dimensions of the image its MEANT to be showing! 😕
  18. Hi Larry, yes the complete path would be: C:\wamp64\www\ch19_uploads all uploaded images of prints end up in that folder. As for the complete path from where my scripts are being run, that would be: C:\wamp64\www\ch19, from here the scripts are being run. so to 'get at' the images, in the scripts the path is usually defined as '..\ch19_uploads' and obviously if i'm in a level 2 folder within ch19, i.e admin, then the path to get at ch19_uploads or the mysqli_connect_ch19.php script would be ..\..\ch19_uploads.
  19. Sorry folks, I had to reply to my own post because I wanted to also share my 'show_image.php' script code with you all: <?php # Script 19.8 - show_image.php // This page retrieves and shows an image. // Flag variables: $image = FALSE; $name = (!empty($_GET['name'])) ? $_GET['name'] : 'print image'; // Check for an image value in the URL: if (isset($_GET['image']) && filter_var($_GET['image'], FILTER_VALIDATE_INT, array('min-range' => 1 )) ) { $image = '../ch19_uploads' . $_GET['image']; // Check that the image exists as a file on the server if (!file_exists($image) || (!is_file($image)) ) { $image = false; } } // End of $_GET['image'] IF. if (!$image) { $image = 'images/unavailable1.png'; $name = 'unavailable.png'; } // Retrieve the image information $info = getimagesize($image); $fs = filesize($image); // Send the file // Prepare the browser to recieve the file based on its MIME type header("Content-Type:{$info['mime']}\n"); // The second line sets the name of the file being sent header("Content-Disposition:inline; filename=\"$name\"\n"); // This last header function indicates how much data is to be expected. header("Content-Length: $fs\n"); // The file data itself is sent using this function below: readfile($image);
  20. Okay, it'll take me a couple of days but I'll test this out on my own server to see what's what.
  21. It's hard to say given the information provided. However, that your code uses 'pass1' suggests this isn't the registration form but rather the password update form. Are you sure you've edited the correct file?
  22. Hi all, I'm running the php files on my machine using the wampserver environment with mysql all scripts/pages are located in the 'www' folder, i.e root directory. Inside the www directory I created a folder 'ch19' and its in this folder where all my files and folders for this chapter reside. so to run the ecommerce example site, the url is localhost/ch19/ ch19 directory contains the following php scripts: index.php, browse_prints.php, show_image.php and view_print.php ( I have not gone as far as the view_cart.php and add_cart.php just yet, will do once I've got this to work..) ch19 has the following folders inside of it: admin includes Both the mysqli_connect.php file and the ch19_uploads folder ( that contain the print images ) are under www but one level above ch19 folder. Ive provided screenshots of what I'm seeing. Notice that when I click on browse_prints.php and then click on a particular print, the print image doesn't appear. Instead, the default 'oops ' image loads in its place. I'm noticing that this default image is taking the dimensions (wxh) of the image of the print thats meant to appear in its place. Odd. When I right click on this image and go to 'view image info' , sure enough the full image path to the print is shown. I wonder why the print image(s) don't load. Here is my code: <?php # Script 19.6 - browse_prints.php // This page displays the available prints (products). // Set the page title and include the HTML header: $page_title = 'Browse the Prints'; include ('includes/header.html'); require ('../mysqli_connect_ch19.php'); // Default query for this page: $q = "SELECT artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, print_id FROM artists, prints WHERE artists.artist_id = prints.artist_id ORDER BY artists.last_name ASC, prints.print_name ASC"; // Are we looking at a particular artist? if (isset($_GET['aid']) && filter_var($_GET['aid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { // Overwrite the query: $q = "SELECT artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, print_id FROM artists, prints WHERE artists.artist_id=prints.artist_id AND prints.artist_id={$_GET['aid']} ORDER BY prints.print_name"; } // Create the table head echo '<section class="bp_tbl"> <div class="bp_tbl_row bp_tbl_row_header"> <div id="tc_artist_name" class="bp_tbl_cell cell_width_20"> <h4>Artist</h4> </div> <div id="tc_print_name" class="bp_tbl_cell cell_width_20"> <h4>Print Title</h4> </div> <div id="tc_description" class="bp_tbl_cell cell_width_50"> <h4>Description</h4> </div> <div id="tc_price" class="bp_tbl_cell cell_width_10"> </h4>Price</h4> </div> </div>'; // Display every returned record: $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { $i = 0; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $i += 1; echo "\t<div id=\"tr_result_$i\" class=\"bp_tbl_row\"> <div id=\"tc_artist_result_$i\" class=\"bp_tbl_cell cell_width_20\"><a href=\"browse_prints.php?aid={$row['artist_id']}\">{$row['artist']}</a></div> <div id =\"tc_print_name_result_$i\" class=\"bp_tbl_cell cell_width_20\"><a href=\"view_print.php?pid={$row['print_id']}\">{$row['print_name']}</a></div> <div id=\"tc_desc_result_$i\" class=\"bp_tbl_cell cell_width_50\">{$row['description']}</div> <div id=\"tc_price_result_$i\" class=\"bp_tbl_cell cell_width_10\">&pound{$row['price']}</div> </div>\n"; } // End of while loop. } else { // no rows returned in result echo '<h4 class="error">Error! database query yielded no results!</h4>'; } echo '</section>'; mysqli_close($dbc); include('includes/footer.html'); ?> <?php # Script 19.7 - view_print.php // This page displays the details for a particular print $row = FALSE; // Validate that a print ID has been passed to this page: if (isset($_GET['pid']) && filter_var($_GET['pid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { $pid = $_GET['pid']; require('../mysqli_connect_ch19.php'); $q = "SELECT CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, size, image_name FROM artists, prints WHERE artists.artist_id=prints.artist_id AND prints.print_id=$pid"; $r = mysqli_query($dbc, $q); // If a record was returned, retrieve the information, set the page title and include the HTML header: if (mysqli_num_rows($r) == 1) { $row = mysqli_fetch_array($r, MYSQLI_ASSOC); $page_title = $row['print_name']; include('includes/header.html'); // Begin displaying the print information: echo "<div align=\"center\"><b>{$row['print_name']}</b> by {$row['artist']}<br />"; echo (is_null($row['size'])) ? '(No size information available)' : $row['size']; echo "<br />&pound{$row['price']}<a href=\"add_cart.php?pid=$pid\">Add to Cart</a></div><br />"; // Display the image: if ($image = @getimagesize ("../ch19_uploads/$pid")) { echo "<div align=\"center\"><img src=\"show_image.php?image=$pid&name=" . urlencode($row['image_name']) . "\" $image[3] alt=\"{$row['print_name']}\" /></div>\n"; } else { echo "<div align=\"center\">No image available.</div>\n"; } // Display the description: echo '<p align="center">' . ((is_null($row['description'])) ? '(No description available)' : $row['description']) . '</p>'; } // End of the mysqli_num_rows() IF. } // End of $_GET['pid'] IF. // If a problem occured, display an error message: if (!$row) { $page_title = 'Error'; include('includes/header.html'); echo '<div align="center">This page has been accessed in error!</div>'; } include ('includes/footer.html'); ?>
  23. Sir, As mentioned in your book the strong password system is good. So I increased the characters required for the password from 6 to 8. if (preg_match('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){8,}$/', $_POST['pass1']) ) { } To test the modification I tried to register with 6 characters password but it had not showed any error and I got registered. Then I cleared the browser's cache and restarted the Apache xampp, but again it had not showed any error and I got registered. Then I decreased the number of password characters to 4 - it had not showed any error and I got registered. Please guide me about this. Thanking You,
  24. Sir, Thank You for encouraging my efforts. I have restarted Apache after making changes and also cleared the cache. But it again showing the above mentioned error. I have visited the link mentioned in your post and there the match is made. So I do not have any idea what could be the problem.
  25. P.S., the script is your script 'sessions.php' just renamed and on your original it is line 53. Up top I just added As per your 'advanced' book.
  26. Hi Larry, Finally got to a point where I could try your suggestion. Sadly, if I applied your suggestion correctly, it did not solve the issue. Please see the attached. The database entry looks OK. Cheers, Necuima
  1. Load more activity
×
×
  • Create New...