Search code examples
phpmysqlprocedure

Why isn't my procedure in MySQL working


So I have this procedure written in MySQL, can anyone tell me why it isn't working?

create procedure add_Order(
    IN custid int,
    IN productid int,
    IN storeid int,
    IN  empid int,
    IN quantity int,
    IN R_payment char(10),
    IN date date)
begin
    insert into Orders(custid, empid, storeid, orderdate) values (IN_cust, IN_empid, IN_storeid, IN_date);
    insert into Order_Product(orderid, productid, quantity, RegisterPayment) values (IN_orderid, IN_productid, IN_quantity, IN_R_payment);
end

This is the error message:

You have an error in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near 'end' at line 1

Solution

  • DROP PROCEDURE IF EXISTS `add_Order`;
    DELIMITER $$
    CREATE PROCEDURE `add_Order`(
        IN custid int,
        IN productid int,
        IN storeid int,
        IN  empid int,
        IN quantity int,
        IN R_payment char(10),IN date date
    )
    BEGIN
        INSERT INTO Orders(custid, empid, storeid, orderdate) values (IN_cust,IN_empid, IN_storeid, IN_date);
        INSERT INTO Order_Product(orderid, productid, quantity, RegisterPayment) values (IN_orderid, IN_productid, IN_quantity, IN_R_payment);
    END
    $$
    
    DELIMITER ;
    

    Reference: https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-stored-procedures.html

    You can also use this tool: http://tools.knowledgewalls.com/mysqlcreateprocedure

    Good Luck!