Hi all, I'm desperately hoping a PHP Jedi can answer this for me...
Is there a way to link PHP script to a button click, so that the script is only activated when someone clicks the "Add to Cart" button for instance?
I ask because some of the items I sell are unique and I have only one of each. I have a mysql database setup and everything is scripted so that an individual item's inventory can be set to zero when it's purchased, which then removes the item from my website so that customers don't even see items that aren't available.
The problem is I can only get my PHP scripts to work on page loads, which means the inventory on my database gets set to zero before a customer clicks the "add to cart" button... so many items get removed from the site even though they haven't even been put in someone's cart yet.
I'd like for my PHP script to tell the database to set the inventory to zero only if someone actually clicks the "Add to Cart" button, not as soon as they get to the "add to cart" page as currently happens... possible? Or am I dreaming?
Any help would be GREATLY appreciated, thanks!
Here's the script I currently have on the final page for these items:
<!--SET STOCK TO ZERO-->
<?
mysql_connect("localhost", "myusername_user", "G~#LM/iOKPwg") or die(mysql_error());
mysql_select_db("myusername_products") or die(mysql_error());
mysql_query("UPDATE watchstrap SET stock='0' WHERE id='1'")
or die(mysql_error());
?>