Online Store / Products Page

Hello everyone. I have been following different tutorials trying to make an online store but I have come across a problem. This code is giving me one of the errors and I do not understand why. I did see that this question was asked before, but the answer was never given on how the writter fixed the problem. The error that is being given is the:

echo "Data to render this page is missing.";

[php]<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
?>

<?php // Check to see the URL variable is set and that it exists in the database if (isset($_GET['id'])) { // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); // Use this var to check to see if this ID exists, if yes then get the product // details, if no then exit this script and give message why $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "That item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <?php echo $product_name; ?>
<?php include_once("template_header.php");?>
<?php echo $product_name; ?>
View Full Size Image

<?php echo $product_name; ?>

<?php echo "$".$price; ?>

<?php echo "$subcategory $category"; ?>

<?php echo $details; ?>

<?php include_once("template_footer.php");?>
[/php]

Hi willscarlet,

I did not review your code thoroughly, but the response you are getting is indicating that either the script is not receiving a $_GET variable named “id” or there is no matching product in the database.

If you are trying to execute the script directly, please note the following:

If you have an id number that you would like to test the script with, call it by inserting “?id=xxxx” (where xxxx is the product id number) at the end of the address for the script.

In other words if your script is at: http://www.myawesomeonlinestore.com/showstuff.php
And you want to see product id 23415
You would put this in your browsers url bar: http://www.myawesomeonlinestore.com/showstuff.php?id=23415

If you are doing this and still getting the error, the next thing to look at is whether the database has a product with that id.

Let me know if this is how you are calling the page and if so, do you have access to the database to verify the product id exists?

Sponsor our Newsletter | Privacy Policy | Terms of Service