0

I cant solve the issue with this code, syntax sql issue maybe.

Have tryed to change in many ways the INSERT sql tag. I dont know if i need to use single quotes or not on this. Tryed both already.

Can anyone help please?

if(isset($_POST['order'])) 
   {


    //values to be inserted in database table
    $order = $_POST['order']; #order
    global $restaurant;
    $request_time = date('H:i'); #request_time
    $status = "requested"; #status
    $date = date("m.d.y"); #date
    $assigned_to = "";

    $mysqli = new mysqli('localhost','foodcour_user','1020304050@','foodcour_db');
        if ($mysqli->connect_error) {
            die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
        }

    $query = "INSERT INTO products (product_code, product_name, price) VALUES(?, ?, ?)";
    $query = "INSERT INTO 'deliverys' ('restaurant', 'order', 'request_time', 'status', 'date', 'assigned_to') VALUES ('?', '?', '?', '?', '?', '?')";
    #$statement = $mysqli->prepare($query);
    if( ! $statement = $mysqli->prepare($query) ) {
  echo 'Error: ' . $mysqli->error;
  return false; // throw exception, die(), exit, whatever...
} else {
  //bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
    $statement->bind_param('ssssss', $restaurant, $order, $request_time, $status, $date, $assigned_to);

if($statement->execute()){
    print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />'; 
}else{
    die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
}

1 Answer 1

1

The following query is wrong

    $query = "INSERT INTO 'deliverys' 
('restaurant', 'order', 'request_time', 'status', 'date', 'assigned_to')
 VALUES ('?', '?', '?', '?', '?', '?')";

get rid off quotes on the column names and table names

order is a reserved word need back ticks ``

get rid off single quotes on ? in bind params

$query = "INSERT INTO deliverys 
(restaurant, `order`, request_time, status, date, assigned_to) 
VALUES 
(?, ?, ?, ?, ?, ?)";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.