Php 通过链接进行SQL注入?

Php 通过链接进行SQL注入?,php,mysql,sql,sql-injection,Php,Mysql,Sql,Sql Injection,这是关于编辑我的数据库表中的两个字段(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

这是关于编辑我的数据库表中的两个字段(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注入?如果可以,如何保护


谢谢大家!

是,因为您没有转义
$\u GET['edit']
。。我们来试试这个:

$old_note_name=mysql_real_escape_string($_GET['edit']);

是,因为您没有转义
$\u GET['edit']
。。我们来试试这个:

$old_note_name=mysql_real_escape_string($_GET['edit']);

是-由于某种原因,您没有转义
$old\u note\u name
,并且在查询结束时,它是最易受攻击的变量。你似乎知道该怎么做。。。对该变量使用
mysql\u real\u escape\u string
,就像对其他变量一样

否则,这就是一切:
/main_edit.php?type=php&edit=note_name2';下拉表功能#

是-由于某种原因,您没有转义
$old\u note\u name
,并且在查询结束时,它是最易受攻击的变量。你似乎知道该怎么做。。。对该变量使用
mysql\u real\u escape\u string
,就像对其他变量一样

否则,这就是一切:
/main_edit.php?type=php&edit=note_name2';下拉表功能#

更改此项:-

$old_note_name=$_GET['edit'];

并将$connection应用于对函数mysql\u real\u escape\u string的所有调用

最后,查看或更改以下内容:-

$old_note_name=$_GET['edit'];

并将$connection应用于对函数mysql\u real\u escape\u string的所有调用


最后,查看或

您可以使用准备好的语句,例如:

$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();

您可以使用准备好的语句,例如:

$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();

如果可以的话,我会+1000这个。停止连接字符串以进行SQL查询,请使用已准备好的语句。您不能信任php脚本中的任何输入,因为恶意用户只需编写自己的html并提交他们想要的任何内容。如果可以,我将+1000。停止连接字符串以进行SQL查询,使用预先准备好的语句。您不能信任php脚本中的任何输入,因为恶意用户可以编写自己的html并提交他们想要的任何内容。仅供参考:通常情况下,在向下投票时留下评论,以便回答者可以改进他们的答案。没有评论的否决票是没有意义的。仅供参考:通常情况下,否决票时会留下评论,以便回答者可以改进他们的答案。不加评论的否决票毫无意义。