2014-04-01 40 views
-1

我正在創建一個電子商務網站並製作訂購系統,但是我的代碼如下所示,出現「數據丟失此頁面丟失」錯誤。我嘗試了各種各樣的工作,但不要縫隙進一步解決這個問題。在php頁面上顯示產品時遇到問題

你能否看看我是否錯過了任何東西或者如果有解決方案這個問題?

在這個階段,我試圖從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(); 
?> 
+1

顯然你的if語句失敗了。這是一個簡單的if語句。 '$ _GET ['clothing_name']'沒有設置。找出爲什麼。 –

+0

'/youtpage.php?clothing_name = 1'你忘了申請'clothing_name' – Jack

+0

@JohnConde,謝謝你的回覆。我會研究它並回復你。 – Priya

回答

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(); 
?> 
+0

添加你提供的一小部分代碼嗎? – Priya

+0

已更新的答案......包含和if語句之間的界線 – Hackerman

+0

感謝您的幫助,但它仍然沒有爲我工作,過去幾天我嘗試了大量不同的東西,並且一直在線上搜索,但無法獲取此內容爲我工作。你會推薦別的嗎? 謝謝你 – Priya

0

首先,您需要傳遞一個QueryString,並在數據庫中有任何記錄。 $_GET[clothing_name]只會在您的QueryString中提供它時設置,因爲您正在測試$_GET[clothing_name]是否由方法isset()設置,所以如果您沒有在querystring條件中提供它,則將爲false,並且您將落入其他條件。

其次定義變量$clothing_name,因爲您在執行SQLQuery之前在查詢中使用它。

$clothing_name = $_GET['clothing_name'];

相關問題