jcrensha627 Posted February 28, 2009 Share Posted February 28, 2009 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> Link to comment https://forums.phpfreaks.com/topic/147271-need-some-help-inserting-or-updating-information/ Share on other sites More sharing options...
mjahkoh Posted February 28, 2009 Share Posted February 28, 2009 This works $time = time(); $password ="mypassword"; $userlevel ="1"; $email ="myemail@domain.com"; $username ="myusername"; $query = "insert into login ( `password`,`userlevel`,`email`,`timestamp`,`username`,`active` ) values ( '".$password."', '".$userlevel."', '".$email."', '".$time."', '".$username."', '".'1'."' )"; echo '$query '.$query.'<br>'; return mysql_query($query, $link); Link to comment https://forums.phpfreaks.com/topic/147271-need-some-help-inserting-or-updating-information/#findComment-773116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.