尝试使用复选框删除多行。起初,我用复选框列生成目录。然后发布数据到php方面。问题是,PHP方面返回到当前页面。这意味着所有成功完成并返回页面的用户返回。但没有成功。在PHP日志和MySQL问题中没有错误。我在$delete=$_POST['delete'];
后试过print_r ($_POST['checkbox']); die();
。它给了我这样的结果Array ([0] => on [1] => on)
我的代码有什么问题?使用复选框从表格删除多个记录(行)
我的HTML标记看起来像
<?php
$result = $db->query("SELECT id, name, showinmenu FROM menu") ;
$num=$result->num_rows;
if ($num>0) {
?>
<form method="post" action="processor/dbdel.php">
<div style="overflow-y: auto; overflow-x: hidden; height:500px">
<table id="list" class="features-table">
<thead>
<tr>
<th>#</th>
<th style="min-width:80px;" class="name">Ad (menyuda işlənən)</th>
<th>Sil</th>
</tr>
</thead>
<tbody>
<?
while ($row = $result->fetch_object()) {
echo '<tr>
<td>'.$row->id.'</td>
<td><a href="'.$wsurl.'admin/?page=edit&id='.$row->id.'">'.$row->name.'</a></td>
<td><input type="checkbox" name="checkbox[]" method="post" value"'.$row->id.'" id="checkbox[]" "/></td>
</tr>';
}
// when the loop is complete, close off the list.
echo "</tbody> <tr id='noresults'>
<td style='text-align:center' colspan='9'>Nəticə yoxdur</td>
</tr></table>
</div>
<p style='text-align:center;'>
<input id='delete' type='submit' name='delete' value='Seçilənləri sil'/> </p>
</form>";
}
?>
这里是我的PHP代码
<?php
require '../../core/includes/common.php';
$delete=$_POST['delete'];
if($delete) // from button name="delete"
{
if (is_array($_POST['checkbox']))
foreach($_POST['checkbox'] as $del_id) {
$del_id = (int)$del_id;
$result=$db->query ("DELETE FROM menu WHERE id = '$del_id'") or die($db->error);
$result2=$db->query ("DELETE FROM pages WHERE id = '$del_id'") or die($db->error);
}
if($result2)
{
header("location:".$wsurl."admin/?page=db");
}
else
{
echo "Error: ".$db->error;
}
}
?>
并且在您阅读了SQL注入攻击之后,请阅读此内容,看看您是否了解它:http://imgs.xkcd.com/comics/exploits_of_a_mom.png – Icarus
谢谢。我们可以继续通过Skype进行讨论吗?我有几个问题 – demonoid
@Marc我修复了。仍然没有成功 – demonoid