0

Im struggling on and now it stopped with an error on the WHERE clause. Cant find the solution to this. If i do SELECT * FROM booking_customer WHERE date_booking_customer = date_input AND time_booking_customer = time_input; its works just fine but together with the rest theres a varning infront of WHERE...

CREATE DEFINER=`root`@`localhost` 
PROCEDURE `book_service`(
date_input DATE,
time_input  TIME,
name_input VARCHAR (200),
member_input TINYINT,
boatname_input VARCHAR (200),
email_input VARCHAR (200),
mobile_input VARCHAR (200)
)

BEGIN
    INSERT INTO booking_customer(
    name_booking_customer, 
    member_booking_customer, 
    boatname_booking_customer, 
    mail_booking_customer, 
    mobile_booking_customer) 
    
    VALUES (
    name_input, 
    member_input, 
    boatname_input, 
    email_input, 
    mobile_input)
    
    WHERE date_booking_customer = date_input 
    AND time_booking_customer = time_input;
END

/Svante

  • This looks to be a duplicate of this question: https://stackoverflow.com/questions/485039/mysql-insert-query-doesnt-work-with-where-clause The INSERT statement does not support the WHERE clause – Alex Collette Jan 03 '21 at 22:22
  • Does this answer your question? [MySQL Insert query doesn't work with WHERE clause](https://stackoverflow.com/questions/485039/mysql-insert-query-doesnt-work-with-where-clause) – Paul T. Jan 04 '21 at 00:09

2 Answers2

1

I am not completely sure what you are attempting to accomplish with the WHERE clause, but INSERT statements cannot have a WHERE associated with them.

It sort of looks like you are trying to update a row WHERE date_booking_customer = date_input and time_booking_customer = time_input. If this is what you are trying to do, you can do this:

UPDATE booking_customer
SET 
    name_booking_customer = name_input, 
    member_booking_customer = member_input, 
    boatname_booking_customer = boatname_input, 
    mail_booking_customer = email_input, 
    mobile_booking_customer = mobile_input
WHERE 
    date_booking_customer = date_input 
    AND time_booking_customer = time_input;
Alex Collette
  • 1,664
  • 13
  • 26
0

Please see The SQL INSERT INTO Statement,https://www.w3schools.com/sql/sql_insert.asp. INSET INTO Statement does not include 'WHERE'.

In a procedure,

IF expression THEN commands
[ELSEIF expression THEN commands]
[ELSE commands]
END IF;

E.g.

IF date_booking_customer == date_input 
   AND time_booking_customer == time_input then
 ...
End If;
Jin
  • 156
  • 1
  • 4