dtwxt88240 2014-10-20 17:00
浏览 45
已采纳

MySQL语法错误说“接近'1'”但我的查询中没有'1'

I'm making a website for the first time using PHP with a MySQL database and getting a syntax error that I don't understand. I just want to delete everything from tblreparation with a certain ID and also everything from rblrepstat with that same ID. I am using this code:

<?php
    $con=mysqli_connect("localhost","root","MYPASS","repair");
    $ID = $_REQUEST['ID'];
    $sql = mysqli_query($con, "DELETE FROM tblreparation WHERE ID = {$ID}");
    if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    $sql = mysqli_query($con, "DELETE FROM tblrepstat WHERE repID = {$ID}");
    if (!mysqli_query($con,$sql)) {
      die('Error2: ' . mysqli_error($con));
    }
    echo "1 record deleted";
    mysqli_close($con); 
?>

And this is the error I am getting:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

Near 1? I don't even see a '1'...

  • 写回答

2条回答 默认 最新

  • douchuo9476 2014-10-20 17:18
    关注

    You're calling mysqli_query twice for each query.

    The second time you call it you're actually passing a resource as the query parameter, which causes the error you're getting.

    Try changing your code to this:

    <?php
        $con=mysqli_connect("localhost","root","MYPASS","repair");
        $ID = $_REQUEST['ID'];
        $sql = "DELETE FROM tblreparation WHERE ID = {$ID}";
        if (!mysqli_query($con,$sql)) {
          die('Error: ' . mysqli_error($con));
        }
        $sql = "DELETE FROM tblrepstat WHERE repID = {$ID}";
        if (!mysqli_query($con,$sql)) {
          die('Error2: ' . mysqli_error($con));
        }
        echo "1 record deleted";
        mysqli_close($con); 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条