Page 1 of 1

need help with inserting or updating info into DB

Posted: Fri Feb 27, 2009 11:37 pm
by jcrensha627
Below I have some php code. It is going to be a sort of stock market simulation. I have created a stock JAME in a table in my db along with the price of it as well as an auto inc id column. Below is what i have so far, I take the stock SYMBOL (JAME) and multiply by the quantity that is provided by the logged in user. this gives me a total purchase cost based on the set price in the table and the quantity posted. what i want is to insert this info into a table in the DB

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>