Forum Moderators: coopster
who purchased it
what they purchased (shares,price,symbol)
<html>
<body>
Go Back to<a href="index.php">Your Portfolio</a>
<br>
<br>
Are you sure you want to buy shares in JAME? (Total Below)
<br>
<br>
<?php
ob_start();
include("config.php");
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href=../login.html>click here</a> to login.");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$get_my_basket = mysql_query("SELECT `symbol`, `price`, `customer` FROM `Athletes` WHERE `customer`='".$username."'");
$total_cost = 0;
$JAME = 0;
$quantity = $_POST['quantity'];
while($my_basket = mysql_fetch_array($get_my_basket))
{
if($my_basket['symbol']=='JAME') $JAME++;
$total_cost += $my_basket['price'] * $quantity;
}
echo 'You have selected: ';
if($JAME > 0)
{
echo $quantity.' JAME shares, ';
}
else
{
echo 'Your Basket it Empty';
}
$total_cost = number_format($total_cost,2);
echo ' and it will cost you $'.$total_cost;
ob_end_flush();
?>
<br>
<br>
Visit<a href="index.php">Your Portfolio</a> to see your purchases.
</body>
</html>
First step is going to be to develop the necessary INSERT statement that will populate the table you have created to store the data. Don't forget to scrub the user data, make sure it is what you expect. Then, always use mysql_real_escape_string [php.net] to condition the user-supplied information before attempting to use it in an sql query statement.