Reputation: 13
I'm trying to create a php include file for my ecommerce website which will be in the centre of the page that will display the products. The database is connected. I have this but it keeps saying "Data to render this page is missing". The variable is not being set. I'm a relative beginner and I dont know what to do.
Thanks in advance!
// 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 "config.inc.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();
}
Upvotes: 0
Views: 458
Reputation: 3054
You are missing an 'id' in the url. The url you are calling should look like this
www.example.com/product.php?id=1
You were getting an error because the script is telling you that there is no 'id' value.
Upvotes: 1