duan02468 2017-02-19 22:23
浏览 43

使用PHP中的预准备语句将爆炸值插入表中[重复]

This question already has an answer here:

I am trying to explode() the $_GET['tri'] variable value (localhost/index.php?tri=*POST BUS*2017-09-01*13:00:00*NDOLA*lusaka*MWILA KAUNDA*0963454336*) and then directly write the explode values to the DB.

Here is the code:

function x(){
    $Conn = new mysqli('127.0.0.1','root','','app');
    //connect
    if (!$Conn->connect_error) {
        //query
        $query = "INSERT INTO POST_BUS (service, day, time, from, to, name, phone) VALUES(?, ?, ?, ?, ?, ?, ?)";
        //prepare stmt
        $stmt = $Conn->prepare($query);
        //explode tri
        $expl = explode('*', $_GET['tri']);
        //categorise
        $service = "$expl[1]";
        $day = "$expl[2]";
        $time = "$expl[3]";
        $from = "$expl[4]";
        $to = "$expl[5]";
        $name = "$expl[6]";
        $phone = "$expl[7]";
        //dispatch tri
        $stmt->bind_param('sssssss','".$service."','".$day."','".$time."','".$from."','".$to."','".$name."','".$phone."');
        //exe
        if ($stmt->execute()) {
            print('success!');
        }
        else{
            die('error');
        }
    }
    else{
        print('try later!!!');
    }
}

i'm getting this error:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\index.php:29 Stack trace: #0 C:\xampp\htdocs\index.php(43): x() #1 {main} thrown in C:\xampp\htdocs\index.php on line 29

Where am I going wrong?

</div>
  • 写回答

1条回答 默认 最新

  • duanlian1320 2017-02-19 22:50
    关注
    $query = "INSERT INTO POST_BUS(service, day, time, `from`, `to`, name, phone) VALUES(?, ?, ?, ?, ?, ?, ?);";
        //prepare stmt
        $stmt = $Conn->prepare($query);
        if (!$stmt) {
           die($Conn->error);
        }
    

    from and to are reserved words and should be quoted. for a complete list of reserved words in mysql please visit the following link

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端