Jump to content
Larry Ullman's Book Forums

dragon_girl

Members
  • Posts

    16
  • Joined

  • Last visited

  • Days Won

    1

dragon_girl last won the day on September 13 2013

dragon_girl had the most liked content!

dragon_girl's Achievements

Newbie

Newbie (1/14)

2

Reputation

  1. Soon I will be moving my test site to a live web server. It's the first time I'm doing this and I was trying to come up with a checklist of things to do when I go live. Here's what I have so far: change how errors are displayed change error reporting set up admin/password for database make sure sensitive files are outside the root folder I'm sure there's more, what did I miss? Thanks.
  2. Thank you for your help in troubleshooting this. When I used $d = NULL without any conditionals it worked. After some google searches I found a solution. It seems that because the description is in a textarea on a form, it behaves differently than an input of type "text". So to get it to work, I can't just check if the textarea is empty. The simple existence of the textarea means it will always have a value, even if that value is an empty string. The only way textarea would be NULL is if the box itself was not instantiated for whatever reason. So both of these will work for me... if (strlen(trim($_POST['description'])) == 0) { $d = NULL; } else { $d = $_POST['description']; } or if (trim($_POST['description']) == '') { $d = NULL; } else { $d = $_POST['description']; } From there I can shorten the code to $d = (trim($_POST['description']) == '') ? NULL : trim($_POST['description']); I guess this makes sense to me. Does this sound legit to you?
  3. in show_print.php.... // If there was a problem, use the default image: if (!$image) { $image = 'images/unavailable.png'; $name = 'unavailable.png'; } When would this conditional return as true (not an image) and therefore use the unavailable.png image?
  4. Hmmm...I thought that's what my conditional was doing: $d = (!empty($_POST['description'])) ? trim($_POST['description']) : NULL; Just for kicks I revised the above to: $d = (!empty($_POST['description']) || ($_POST['description'] != ' ')) ? trim($_POST['description']) : NULL; and: if (empty($_POST['description']) || ($_POST['description'] == '')) { $d = NULL; } else { $d = trim($_POST['description']); } Both with the same results, NULL has not been inserted into database.
  5. Thank you, that does make sense. But at what point would show_print.php trigger the use of the default unavailable image?
  6. view_print.php: <?php # Script 19.7 - view_print.php // This page displays the details for a particular print. // $row is used to track whether or not a problem occurred on this page // if ok, this var will store the print info from the db // if not ok, this var will still be FALSE and the page should create an error $row = FALSE; // make sure there's a print id and that the print id is an int greater than or equal to 1 // pid comes from browse_prints.php if (isset($_GET['pid']) && filter_var($_GET['pid'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $pid = $_GET['pid']; // get the print info require('includes/mysqli_connect.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 (mysqli_num_rows($r) == 1) { // fetch the info $row = mysqli_fetch_array($r, MYSQLI_ASSOC); // start the html page $page_title = $row['print_name']; include('includes/header.html'); // display a header echo '<div align="center"><b>' . $row['print_name'] . '</b> by ' . $row['artist'] . '<br />'; // print the size or a default msg echo (is_null($row['size'])) ? '(No size available)' : $row['size']; echo "<br />\${$row['price']}<a href=\"add_cart.php?pid=$pid\">Add to Cart</a></div><br />"; // get the image info and display image; // because the images are stored outside the root dir, show_image.php is required // to provide the image to the browser; // getimagesize() returns an array with 7 elements; // $image[3] refers to a text string with the correct height="yy" width="xx" string // that can be used directly in an img tag; if ($image = @getimagesize("../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><br />'; } // add the description or a default message echo '<p align="center">' . ((is_null($row['description'])) ? '(No description available.)' : $row['description']) . '</p>'; } mysqli_close($dbc); } 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'); ?> show_image.php: <?php # Script 19.8 - show_image.php // This pages 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)) ) { // Full image path: $image = '../uploads/' . $_GET['image']; // Check that the image exists and is a file: if (!file_exists ($image) || (!is_file($image))) { $image = FALSE; } } // End of $_GET['image'] IF. // If there was a problem, use the default image: if (!$image) { $image = 'images/unavailable.png'; $name = 'unavailable.png'; } // Get the image information: $info = getimagesize($image); $fs = filesize($image); // Send the content information: header ("Content-Type: {$info['mime']}\n"); header ("Content-Disposition: inline; filename=\"$name\"\n"); header ("Content-Length: $fs\n"); // Send the file: readfile ($image);
  7. I was trying to break my ecommerce program to see how everything worked. One of the things I did was delete an image that was in the uploads folder. When I went to view_print.php for that specific image I did get the message "No image available." that was echoed from view_print.php. Why, instead, did it not use the default unavailable.png image that was set up in show_image.php?
  8. Go back to page 179 in the book. It states that the index name is optional. When indexing multiple columns, in this case username and password, separate them by commas and put them in order of importance. So all you're doing is indexing 2 columns at once and giving this multiple index a name of login.
  9. When using the add_print.php script, if I add a description to the description field, the database inserts the string value. However, when I don't enter a description, instead of inserting NULL, an empty value is inserted. So when I view a specific print that does not have a description, no message is displayed. If I go into my database and manually change the empty description field to NULL and redisplay the print page, my (No description) message is shown. Any ideas why this is happening. My check for description: $d = (!empty($_POST['description'])) ? trim($_POST['description']) : NULL; My query: $q = 'INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES (?, ?, ?, ?, ?, ?)'; $stmt = mysqli_prepare($dbc, $q); mysqli_stmt_bind_param($stmt, 'isdsss', $a, $pn, $p, $s, $d, $i); mysqli_stmt_execute($stmt);
  10. I'm working on Chapter 18 registration application. I noticed in the book that in the config.inc.php file the constants are defined as define('LIVE', FALSE); In mysqli_connect.php the constants are defined as DEFINE ('DB_USER', 'username'); What is the difference between the two? Why is define in all-caps in the second example?
×
×
  • Create New...