Jump to content
MakeWebGames

Recommended Posts

Posted

I read about procedures on the mysql website and tried to give it a go, I however cannot seem to create even a simple procedure. Any suggestions? this is what i have come up with so far..

CREATE PROCEDURE buyShopItem

(item INT(11),shop INT(11),user INT(11),itemCost INT(11))

BEGIN

DELETE FROM `userShopItems` WHERE `itemId` = item;

UPDATE `userShops` SET `shopStock` = `shopStock` - '1' WHERE `shopId` = shop;

UPDATE `users` SET `money` = `money` - itemCost WHERE `userid` = user;

END;

Posted

Re: MySQL Procedures

I'm going to go out on a limb here and assume you are using phpMyAdmin to create this procedure. If you are then you need to do the following or it won't work:

Click the SQL tab enter the following for the SQL

DROP PROCEDURE IF EXISTS buyShopItem $$
CREATE PROCEDURE buyShopItem(item INT(11), shop INT(11), user INT(11), itemCost INT(11))
BEGIN
DELETE FROM `userShopItems` WHERE `itemId` = item;
UPDATE `userShops` SET `shopStock` = `shopStock` - 1 WHERE `shopId` = shop;
UPDATE `users` SET `money` = `money` - itemCost WHERE `userid` = user;
END $$

 

below where you enter the SQL there should be a text field called delimeter, enter $$

click Go and it should now work for you

also don't do field = field - '1'

'1' is a char, not a number ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...