2014-01-10 176 views
-3

好了,我有一個SELECTPHP/SQL刪除按鈕的每一行

$filme_cart = mysql_query("SELECT name, price FROM cart_test GROUP BY name"); 

,然後我有一個PHP代碼,看起來像這樣:

<?php                 
    while($film_cart=mysql_fetch_object($filme_cart)) 
    {               
    echo "<tr>";                
    echo "<td align='left'>";                 
    echo $film_cart->name;                
    echo "</td>";                
    echo "<td class='cart-product-setting'>";                
    echo $film_cart->price;                 
    echo "<a href='delete.php?delete_film=".$film_cart['id_film']."' class='remove-pro' rel='tooltip' data-title='Delete'><i class='icon-trash'></i></a></td>";                
    echo "</tr>"; 
} 
?> 

而且我delete.php文件看起來是這樣的:

<?php 
include 'config.php'; 
$delete_film=$_GET['id_film']; 
$delete_cart = mysql_query("DELETE FROM cart_test WHERE id_film='$delete_film'"); 
?> 

所以,當我把PHP代碼在我的網頁,我<body>消失。

我在做什麼錯?

+3

什麼會消失? –

+1

請修復該格式。 –

+0

@AbhikChakraborty 「This disappear」 and

This

回答

1

您使用mysqli或PDO
你已經錯過了3要點:

修復您的查詢: 1)確保您選擇了所有必填字段。

$filme_cart = mysql_query("SELECT * FROM cart_test GROUP BY name"); 

2)嘗試使用:mysql_fetch_assoc

<?php 
    while($film_cart=mysql_fetch_assoc($filme_cart)) 
     { 
     echo "<tr>"; 
     echo "<td align='left'>"; 
     echo $film_cart['name']; 
     echo "</td>"; 
     echo "<td class='cart-product-setting'>"; 
     echo $film_cart['price']; 
     echo "<a href='delete.php?delete_film=".$film_cart['id_film']."' class='remove-pro' rel='tooltip' data-title='Delete'><i class='icon-trash'></i></a></td>"; 
     echo "</tr>"; 
    } 
    ?> 

然後:3) GET值由$_GET['delete_film']

<?php 

include 'config.php'; 

$delete_film=$_GET['delete_film']; 

$delete_cart = mysql_query("DELETE FROM cart_test WHERE id_film=$delete_film limit 1"); 

?> 
+0

@ user3175636:它應該是工作。你可以試試這個嗎? –

+0

它是這樣工作,但現在我有另一個電影名稱和價格問題。 注意:試圖在第122行的E:\ localhost.web \ temabd \ index-2.php中獲取非對象的屬性 –

1

的GET參數被稱爲delete_film不id_film

所以解決這一行

$delete_film=$_GET['id_film']; 

與這一個

$delete_film=$_GET['delete_film']; 
+0

謝謝,但它不是來自這裏。 –

+0

@ user3175636打印var $ delete_film,如果它丟棄了數據,那麼可能是空的。 – Goikiu

0

1 - 你需要從數據庫
選擇id_film mysql_query("SELECT id_film, name, price FROM cart_test GROUP BY name");
2 - 您使用mysql_fetch_assoc來獲取數據,所以你應該呼應像數據:
echo $film_cart['name'];
不喜歡:
echo $film_cart->name;
3 - 的GET參數被稱爲delete_film不id_film,所以用得值:
$delete_film=$_GET['delete_film'];
4 - MySQL是在PHP 5.5過時,你應該使用PDO或mysqli的
好運