2013-01-13 74 views
0

我一直在這個項目上工作了很長一段時間,仍然陷在這段代碼中。此處,我可以展示產品列表頁:從列表中選擇產品

@mysql_connect("localhost", "root", "") or die(); 
@mysql_select_db("product") or die(); 

$result=mysql_query("select * from product_list ORDER BY name ASC"); 
while($row=mysql_fetch_array($result)){ 
    a href="show.php?code=$row['serial']|$row['name'] 
    $row['description'] 

show.php是:

//connect to server and select database; you may need it 
@mysql_connect("localhost", "root", "") or die(); 
@mysql_select_db("bibendum") or die(); 

$serial = intval($_GET['serial']); 
$query = "SELECT serial, name, desription FROM product_list WHERE serial = {$serial}"; 

echo "{$row[name]}"; 

我得到這個錯誤:

Notice: Undefined index: serial in show.php on line 7
Notice: Undefined index: serial in show.php on line 8
Notice: Use of undefined constant name - assumed 'name' in show.php on line 10
Notice: Undefined variable: row in show.php on line 10

回答

0

我想這:

$serial = intval($_GET['serial']); 
$query = "SELECT serial, name, desription FROM product_list WHERE serial = {$serial}"; 

echo "{$row[name]}"; 

應該是這樣的:

$serial = intval($_GET['code']); 
$query = "SELECT serial, name, desription FROM product_list WHERE serial = '".$serial."'"; 
echo $row['name']; 

在上面你分配查詢,但你仍然需要執行查詢來獲得結果。

,這將無法正常工作通過$ _GET:

a href="show.php?code=$row['serial']|$row['name'] 
$row['description'] 

如果你正在學習不要使用MySQL的使用.....庫MySQLi或PDO

0

開始我也提醒你檢查$ _GET ['serial']是否有效並且不是例如0.