dongxian5735 2016-01-14 10:39
浏览 32
已采纳

通过$ _GET [duplicate]传递变量时SQL中的错误查询

This question already has an answer here:

Here is the query:

$table = $_GET['type'];
$q="DELETE FROM '$table' WHERE cont_id='".$_GET['where']."'";

I also tried removing the single/double quotes on the $_GET part, but didn't work. I'm printing the values of my variables before executing the query and they are right so I don't think that's the problem.

Any ideas?

</div>
  • 写回答

3条回答 默认 最新

  • dongzhan3937 2016-01-14 10:41
    关注

    Database table names should not be enclosed with single quotes.

    Corrected SQL:

    $q="DELETE FROM $table WHERE cont_id='".$_GET['where']."'";
    

    Tables and field names can be enclosed with backticks (`) to avoid clashes with

    MySQL reserved keywords.

    In that case, corrected SQL should be:

    $q="DELETE FROM `$table` WHERE `cont_id` = '".$_GET['where']."'";
    

    Also, do not trust input from user.

    This can cause security vulnerability.

    use mysqli_real_escape_string() for $_GET['where']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 全志v3s怎么设置高速时钟,使用的荔枝派zero开发板,串口2需要921600的波特率
  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁
  • ¥15 bywave配置文件写入失败
  • ¥20 基于Simulink的ZPW2000轨道电路仿真
  • ¥15 pycharm找不到在环境装好的opencv-python
  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)