Online PHP Shop Help
Posted: Sun Jun 21, 2009 7:54 pm
Right now I'm trying to create a online store in PHP (no real money, just tokens). I have a few problems. First, I have no idea how to know if the user has enough tokens to buy the an object, and second I don't know how it would record what they buy to a MySQL database. Can I have any help? I wrote a small script with an idea of how I will do it:

Code: Select all
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
require '/home/username/public_html/folder/config.php';
$username = mysql_real_escape_string($_SESSION['username']);
$price = mysql_real_escape_string($_POST["price"]);
$pro = mysql_real_escape_string($_POST["product"]);
$sql = "UPDATE users SET tokens=(tokens-$price) WHERE username='$username'";
mysql_query($sql);
echo "Thank you for buying $pro!";
?>