當我點擊刪除按鈕。第二頁不會刪除查詢,而是說:查詢中出現錯誤:沒有選中數據庫選中的行被刪除。我想刪除選定的查詢。查詢時發生錯誤:
我應該包括哪些代碼,以便第二頁重定向到第一頁?
query4.php
<html>
<title> Queries</title>
<body>
<h1> List of Queries</h1>
<form method=post action="delete4.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>
delete4.php
<?php
if (isset($_POST['Delete']))
{
foreach ($_POST['Query'] as $checkbox)
{
echo "$checkbox";
$conn= mysql_connect("localhost","root","") or die(mysql_error());
$sql = mysql_select_db("testdb") or die(mysql_error());
$del = mysql_query("DELETE * FROM queries WHERE queryId=$checkbox");
$rs = mysql_query($del) or die(mysql_error());
if($rs)
{
echo ("Records Deleted");
}
else
{
echo ("No Way");
}
}
}
?>
您需要重新連接到每個頁面上的數據庫。 – 2011-05-28 08:41:55
如果我使用此代碼:<?PHP 如果(isset($ _ POST [ '刪除'])) { 的foreach($ _POST [ '查詢']爲$複選框) { 回聲 「$複選框」; $ conn = mysql_connect(「localhost」,「root」,「」)或die(mysql_error()); $ sql = mysql_select_db(「testdb」)或死(mysql_error()); $ del = mysql_query(「DELETE * FROM queries WHERE queryId =」。$ checkbox); $ rs = mysql_query($ del)或die(mysql_error()); if($ rs) { echo(「Records Deleted」); } \t else { echo(「No Way」); } } } ?> – teana 2011-05-29 07:44:50
@teana在評論中很難閱讀 - 我想說試試吧 – 2011-05-29 07:46:21