查询未插入foreach的mysqli中

时间:2018-10-15 04:22:51

标签: php mysql mysqli

每次我尝试插入数据库时​​,都会不断得到:

  

您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获取正确的语法,以在第1行的“至,从,座位,票价”附近使用值(“ 1”,“ Akinwale”,“ male”,“ fagbemiayodele48 @ gmai”

我有以下查询:

if(isset($_POST["psubmit"])){

     $seats = $_POST["seats"];
    // $remove[] = "'";
    //$remove[] = '"';
    //$remove[] = "-"; // just as another example

   // $FileName = str_replace( $remove, "", $seats);
   $val = explode(",", $seats);
   $get =  var_dump($val);

    $query = "INSERT INTO booking (bus_no, name, gender, email, phone, next_of_kin_name, next_of_kin_phone, date_time, to, from,seats, fare) 
    VALUES ";
            foreach($_POST["fname"] as $i => $fname) 
            { 

            // Get values from post.
            $bid = $_POST["bid"]; 
            $bno = $_POST["bus_no"];    
            $from = $_POST["from"];
            $to = $_POST["to"];
            $amount = $_POST["paying_amt"];
            $date = $_POST["d_date"];

            $amt = $_POST["paying_amt"];
            $nkn = $_POST["nokn"];
            $nkp = $_POST["nokp"];
            $seats = $_POST["seats"];
            //$val = !is_array($seats) ? explode(",", $seats) : $seats;

            $email = $mysqli->real_escape_string($_POST["email"]);
            $mobile =  $mysqli->real_escape_string($_POST["phone"]);
            $fname =  $mysqli->real_escape_string($_POST["fname"][$i]);
            $gender =  $mysqli->real_escape_string($_POST["gender"][$i]);
            //$value = $mysqli->real_escape_string($val[$i]);

            // Add to database
            $query .= "('$bid','$fname','$gender','$email','$mobile','$nkn','$nkp','$date','$to','$from','$get','$amount'),";
            }
            $query = substr($query,0,-1); //remove last char
            $result = mysqli_query($mysqli,$query);

            if($result) {
               echo 'done';
            }
            else {
                echo $mysqli->error;
            }

}

请问我在做什么错。我已经尝试了所有可能的方法,但是仍然没有进展。

有人可以指出我正确的方向吗?

0 个答案:

没有答案