0
我试图通过输入从表单中删除mysql行数据。我无法从我的表中删除数据或丢失任何错误。我只是想在我想从我的数据库中删除的ID中输入我的表单。删除mysql中的行通过表单输入编号
<?php
$con = mysql_connect("localhost","root","######");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql = mysql_query("DELETE FROM `Blog` WHERE `Id` = '$id'") or die (mysql_error());
$id = $_GET['Id'] ;
?>
<form action="#" method="get">
Delete: <input type="text" name="Id"><br>
<input type="submit" value="delete">
</form>
要指定'$ id' _after_你使用它。 –
你必须首先[通过彻底阅读这个问题](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)。你的代码容易受到SQL注入攻击,事实上,任何人都可以轻松地删除表中的所有内容。打开error_reporting并在屏幕上显示错误(始终在开发代码时),您将看到有关未定义变量的通知。 '的error_reporting(E_ALL); ini_set('display_errors',1);' –
好的,谢谢迈克尔。我将$ id移到了查询上,现在它可以工作。我曾试着附加你给我的error_reporting,但每次都会中断。 –