2012-03-14 2 views
0

私は、商品を表示するページの中心にある私のeコマースウェブサイト用のPHPインクルードファイルを作成しようとしています。データベースが接続されています。私はこれを持っていますが、 "このページをレンダリングするためのデータはありません"と続きます。変数が設定されていません。私は相対的な初心者で、私は何をすべきか分からない。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(); 
} 
+4

'$ _GET ['id']'が設定されていません。 – hakre

+0

@hakreどうすれば設定できますか?素早い返信ありがとう – user1269822

+2

このページのアドレスが何であっても、クエリ文字列に 'id = something'を入れましたか? –

答えて

1

URLに「ID」がありません。あなたが呼び出しているURLは、スクリプトが何の「ID」値がないことを通知されているため、あなたがエラーを取得したこの

www.example.com/product.php?id=1 

のようになります。

+0

'www.example.com/product.php?id = 1' –

+0

はい私はid = 1を大胆にしようとしましたが、それらの面白いアスタリスクを追加しました:) –

+0

基本的に私はテンプレートのヘッダー、フッター、左のナビゲーションと右のブロック。これはテンプレートの中に入る中間のインクルードです。私は左のナビゲーション - 「製品」をクリックすると、データベースから製品を引き出したいと思います。だから、IDの権利はないはずですか? – user1269822

関連する問題