它是关于编辑我的数据库表中的两个字段(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 注入(inject),如果是,如何防止它?
谢谢!
最佳答案
您可以使用准备好的语句,例如:
$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();
关于php - 通过链接进行 SQL 注入(inject)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8493417/