Hey,

I am trying to create this EVENT via phpmyadmin, but I get a syntax error which I cant see:

This is the code for the event:

DELIMITER | 
CREATE 
EVENT delete_cart 
ON SCHEDULE EVERY 5 MINUTES
DO 
BEGIN 
DECLARE cartID INTEGER;

DECLARE cartProductID INTEGER;

DECLARE cartAntal INTEGER;

DECLARE cartStr VARCHAR;

SELECT id, produkt_id, antal, str INTO cartID, cartProductID, cartAntal, cartStr FROM cart WHERE added_date >= added_date +10000 LIMIT 1;

UPDATE products SET stock = stock + cartAntal WHERE produkt_id = cartProductID;

UPDATE sizes SET antal = antal + cartAntal WHERE size = cartStr AND product_id = cartProductID;

DELETE FROM cart WHERE id = cartID;

END | 
DELIMITER;

The error message returned is as follows:

#1064 - 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 'MINUTES DO BEGIN DECLARE cartID INTEGER; DECLARE cartProductID INTEGER; ' at line 3

Yep you are right, thanks :-)

delimiter | CREATE EVENT delete_cart ON SCHEDULE EVERY 5 MINUTE DO BEGIN DECLARE cartID INTEGER( 11 ) ;

DECLARE cartProductID INTEGER( 11 ) ;

DECLARE cartAntal INTEGER( 11 ) ;

DECLARE cartStr VARCHAR( 5 ) ;

SELECT id, produkt_id, antal, str
INTO cartID, cartProductID, cartAntal, cartStr
FROM cart
WHERE added_date >= added_date +10000
LIMIT 1 ;

UPDATE products SET stock = stock + cartAntal WHERE produkt_id = cartProductID;

UPDATE sizes SET antal = antal + cartAntal WHERE size = cartStr AND product_id = cartProductID;

DELETE FROM cart WHERE id = cartID;

END | delimiter;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.