这是关于编辑我的数据库表中的两个字段(note_name和note_description),我从链接中获取了一些信息,并从一个表单中获取了新字段:
链接:
/main_edit.php?edit=note_name2&type=PHP和:
elseif(isset($_GET['edit'])){
$note_type=$_GET['type'];
$old_note_name=$_GET['edit'];
$new_note_name=mysql_real_escape_string($_POST['new_note_name']);
$new_note_description=mysql_real_escape_string($_POST['new_note_description']);
$query="UPDATE functions
SET note_name='{$new_note_name}',
note_description='{$new_note_description}'
WHERE note_name='{$old_note_name}'
";
$result = mysql_query($query, $connection);}这里是否可以通过链接进行SQL注入?如果可以,如何保护它?
谢谢!
发布于 2011-12-14 01:27:04
是的-由于某些原因,您无法转义$old_note_name,并且由于它位于查询的末尾,因此它是最易受攻击的变量。你似乎知道该怎么做...在该变量上使用mysql_real_escape_string,就像在其他变量上一样。
否则,这就是它所需要的:/main_edit.php?type=PHP&edit=note_name2';drop table functions;#
发布于 2011-12-14 01:35:06
您可以使用预准备语句,如下所示:
$query = "UPDATE functions SET note_name=?, note_description=? WHERE note_name=?";
$statement = $connection->prepare($query);
$statement->bind_param('sss', $new_note_name, $new_note_description, $old_note_name);
$statement->execute();发布于 2011-12-14 01:26:30
是的,因为你不是在逃避$_GET['edit'] ..试试这个怎么样:
$old_note_name=mysql_real_escape_string($_GET['edit']);https://stackoverflow.com/questions/8493417
复制相似问题