在php页面上显示产品的麻烦

时间:2014-04-01 18:01:30

标签: php mysql sql phpmyadmin

我正在创建一个电子商务网站并制作一个订购系统,但是我的代码如下所示,我收到错误"数据使这个页面丢失"。我已经尝试了各种各样的工作但是没有接缝以便进一步解决这个问题。

请问您是否遗漏了任何问题或是否有解决方案?

在这个阶段,我试图从sql数据库中显示我的产品

感谢您的帮助

 <?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['clothing_name'])) {
 // Connect to the MySQL database  
    include "/xampp/htdocs/website/connection.php"; 

 $sql = mysql_query("SELECT * FROM items WHERE clothing_name='$clothing_name' LIMIT 1");
 $productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
  // get all the clothing details
  while($row = mysql_fetch_array($sql)){ 
    $clothing_name = $row["clothing_name"];
    $size = $row["size"];
    $price = $row["price"];
    $details = $row["details"];

         }

 } else {
  echo "That item does not exist.";
     exit();
 }

} else {
 echo "Data to render this page is missing.";
 exit();
}
mysql_close();
?>

2 个答案:

答案 0 :(得分:1)

将此添加到您的代码中:

$clothing_name = $_GET['clothing_name'];

更新

 <?php 
 // Script Error Reporting
 error_reporting(E_ALL);
 ini_set('display_errors', '1');

 // Check to see the URL variable is set and that it exists in the database
 if (isset($_GET['clothing_name'])) {
 // Connect to the MySQL database  
 include "/xampp/htdocs/website/connection.php"; 
 $clothing_name = $_GET['clothing_name']; //HERE
 $sql = mysql_query("SELECT * FROM items WHERE clothing_name='".$clothing_name."' LIMIT 1");
 $productCount = mysql_num_rows($sql); // count the output amount
 if ($productCount > 0) {
  // get all the clothing details
  while($row = mysql_fetch_array($sql)){ 
   $clothing_name = $row["clothing_name"];
   $size = $row["size"];
   $price = $row["price"];
   $details = $row["details"];

     }

   } else {
 echo "That item does not exist.";
 exit();
 }

} else {
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>

答案 1 :(得分:0)

首先,您需要传递一个QueryString,数据库中有任何记录。仅当您在QueryString中提供$_GET[clothing_name]时才会设置$_GET[clothing_name],因为您正在测试isset()是否由方法$clothing_name设置,因此如果您未在查询字符串条件中提供它将为false并且你会陷入其他状态。

其次,在执行SQLQuery之前,在查询中使用变量$clothing_name = $_GET['clothing_name'];

{{1}}