0
我的查詢沒有從表中刪除。我也希望它在刪除後返回到第一頁。使用PHP從MySQL表中刪除行
<html>
<title> Queries</title>
<body>
<h1> List of Queries</h1>
<form method=post action="delete7.php">
<?php
$ebits = ini_get('error_reporting');
error_reporting($ebits^E_NOTICE);// Turns off all the notices &warnings
mysql_connect("localhost","root","") or die(mysql_error());//Connects to the DB
mysql_select_db("testdb") or die(mysql_error()); //Selects one database
echo "<br />";
$query = "select * from queries ";
$result = mysql_query($query) or die(mysql_error()); //sends a unique query to active database on the server
$count=mysql_num_rows($result);
echo "<table border=\"1\">";
echo "<th><tr><td> </td><td>Name</td><td>Address</td><td>ContactNo</td><td>Query</td></tr></th>";
while($row = mysql_fetch_array($result))
{
echo"<tr>";
echo"<td><input type='checkbox' name='Query[]' value=\"".$row['queryId']."\"> </td>";
echo " <td>" . $row['name'] . "</td><td>" . $row['address'] . "</td><td>" . $row['contactNo'] . "</td><td>" . $row['query'] . "</td>";
echo"</tr>\n";
}
?>
<input type="submit" value="Delete" name="Delete"> <br/>
</form>
</body>
</html>
<?php
$conn = mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db("testdb") or die(mysql_error());
if (isset($_POST['Delete']))
{
foreach ($_POST['Query'] as $checkbox)
{
echo "$checkbox";
$del = mysql_query("DELETE * FROM queries WHERE queryId=
$checkbox") or die(mysql_error());
if($del)
{
echo ("Records Deleted");
}
else
{
echo ("No Way");
}
}
}
?>
它可以幫助把正確的查詢,太:'DELETE FROM查詢的WHERE queryId = $ checkbox'(DELETE後沒有'*')。另外,如果你看到這樣的代碼,請解釋一下SQL注入... – Konerak 2011-06-09 06:17:26
Konerak,你爲什麼不自己解釋SQL注入? :-) – 2011-06-09 06:19:00
謝謝:) :)。我只需要移除這顆星星。你能告訴我哪個coe應該補充說第二頁返回到刪除後的第一頁 – teana 2011-06-10 05:13:35