我正试图为我的电子商务网站创建一个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 "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();
}
您在url中缺少一个"id"。你正在调用的url应该像这个
www.example.com/product.php?id=1
您收到一个错误,因为脚本告诉您没有"id"值。