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\">£{$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 />£{$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');
?>