doudang1052 2012-03-10 17:25
浏览 105
已采纳

无法获取mysql查询以使用双引号或单引号[重复]

This question already has an answer here:

I am scratching my head to make this lines of code to work, but no success...Would be nice if someone can point out what is the best practice to write such queries?

if(isset($_POST) && $_POST["id"] > 0)
{
    include('../../config.php');            

    $id = $_POST["id"];
    $title = mysql_real_escape_string($_POST["title"]);
    $desc = mysql_real_escape_string($_POST["desc"]);        

    $cat = $_POST["catid"];

    $_DB->Execute("UPDATE gallery_imgs SET title = `$title`, description = `$desc` WHERE id = $id");

    header("location: admin.php?mode=images&id=$cat");
}
else
{
     //Other stuff!
}

This is the error I get:

Error number: 1054
Error       : Unknown column 'The SIEK!' in 'field list'
</div>
  • 写回答

3条回答 默认 最新

  • dtnbjjq51949 2012-03-10 17:27
    关注

    First, you have called mysql_real_escape_string() on the string values, but you must also validate the contents of $_POST['id'].

    // invalid string values will convert to integer 0
    // If that is not allowable, you should not proceed with the query.
    $id = intval($_POST['id']);
    

    Input strings must be enclosed in single quotes, not backquotes (which are used for column and table identifiers);

    $_DB->Execute("UPDATE gallery_imgs SET title = '$title', description = '$desc' WHERE id = $id");
    

    As an aside, you should validate the contents of $_POST['catid'] before using it in a redirection header. For example, if it is supposed to be numeric:

    // At least cast it to an int if it is an invalid string....
    $catid = intval($_POST['catid']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择