Jump to content

Easy Question: echo and return?


Thauwa
 Share

Recommended Posts

Hey people!

 

I've been setting a coding script for experience and this is my situation:

 

To buy a virtual flower, one needs to have 50 virtual coins.

So I first extract the number of coins the person has from the DB.

If the user doesn't have the sufficient number of coins, the BUY button will not be available and vice versa.

 

When the BUY button is clicked, I update the database, adding the flower to the user's inventory and subtracting 50 from the total number of coins the user has. This I do in that page itself using

if(isset($_POST['submit'])) 

 

Now, I need to know how I could check whether the user has at least 50 coins even if the button is available.

I hope that you could understand this.

I want to do it for validation purposes. Its to prevent the user spending the coins he has in another browser window and then returning to the visible button to click it.

 

I hope that I make sense. Thanks in advance!

 

Regards,

Thauwa

Link to comment
Share on other sites

You probably want to add an onSubmit function that will check how many coins they have, and if they still have 50 in the database, they will be able to purchase the flower.

 

Otherwise, you will show a message saying they don't have enough coins. (The form action won't run if the onSubmit function returns invalid - or something like that. Best to google it :) )

 

Hope that helps

 

Denno

Link to comment
Share on other sites

This thread is more than a year old.

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.   Restore formatting

  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.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.