2017-02-19 52 views
0

我正在嘗試explode()變量值 (localhost/index.php?tri=*POST BUS*2017-09-01*13:00:00*NDOLA*lusaka*MWILA KAUNDA*0963454336*)然後直接將爆炸值寫入數據庫。使用PHP中的準備語句將爆炸值插入表中

下面是代碼:

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!!!'); 
    } 
} 

我得到這個錯誤:

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

我要去哪裏錯了?

+0

$ stmt是聲明和$ conn是連接hundle – Bool

+0

谷歌錯誤消息。使用該錯誤作爲您的標題。你會在2分鐘內自己找到答案。 –

回答

1
$query = "INSERT INTO POST_BUS(service, day, time, `from`, `to`, name, phone) VALUES(?, ?, ?, ?, ?, ?, ?);"; 
    //prepare stmt 
    $stmt = $Conn->prepare($query); 
    if (!$stmt) { 
     die($Conn->error); 
    } 

是保留字,應該被引用。爲mysql的保留字的完整列表請visit the following link