我正在尝试在选中特定复选框时从数据库中删除一行 - 但即使它声明成功,它也不会删除。任何帮助表示赞赏!
我的sql代码如下:
if(isset($_POST['delete'])){
$NetID = $_POST['employee'];
$allEmployees = $mysql->prepare("SELECT * FROM ITS_Employees WHERE NetID = '$NetID'") or die('Could not query:' . mysql_error());
$allEmployees-> execute();
$allEmployees-> bind_result($id, $fn, $ln, $level);
$mysql->query("DELETE FROM ITS_Employees WHERE NetID = '$NetID'");
echo $NetID;
echo'You have successfully deleted the employee(s)!';
echo "<a href='login.php'>Back to main page</a>";
}
我的html / php看起来像这样:
<form action="addDB.php" method="post">
<?php
$employeeQuery = $mysql ->prepare("SELECT DISTINCT FirstName, LastName, NetID, Level FROM ITS_Employees") or die(mysql_error());
$employeeQuery-> execute();
$employeeQuery-> bind_result($fn, $ln, $id, $level);?>
<?php while($employees = $employeeQuery->fetch()){
$name = ( $fn .' '. $ln );
echo '<input type="checkbox" name="employee" value="'.$id.'" /> '. $name .' ('.$level.')</br>';
}//print_r($employee)
;
?>
<input type="submit" name="delete" value="Delete Employee" />
</form>
答案 0 :(得分:0)
try =&gt; DELETE FROM ITS_Employees WHERE NetID = $NetID"
没有单引号