jcrensha627 Posted February 28, 2009 Share Posted February 28, 2009 below i have a written code that takes info from a table on a db and does a calculation. I want be able to add information to another table named trades, i thought this could be done using my $insert query below. I want to insert in the table trades the following: an auto inc ID,JAME,what was posted to the quantity box and finally the total cost of the transaction. also im tryin to add the logged in users name to a colum in trades. my errors are below. so if user jimbo bought 10 JAME at $50/JAME =$500 i want the table to show this in the db id | JAME | 10 | $500.00 | Jimbo Code: <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` FROM `Athletes` WHERE `symbol`='".JAME."'"); $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; $insert = mysql_query("insert into trades values ('NULL', 'JAME', '".$_POST['quantity']."', '.$total_cost')") or die("Could not insert data because ".mysql_error()); ob_end_flush(); ?> <br> <br> Visit<a href="index.php">Your Portfolio</a> to see your purchases. </body> </html> MY ERROR ---------- Are you sure you want to buy shares in JAME? (Total Below) You have selected: 10 JAME shares, and it will cost you $500.00Could not insert data because Column count doesn't match value count at row 1 ??? Link to comment https://forums.phpfreaks.com/topic/147336-simple-insert-question-im-missing-somethign-easy/ Share on other sites More sharing options...
dt192 Posted February 28, 2009 Share Posted February 28, 2009 your only inserting 4 items into a 5 column table Link to comment https://forums.phpfreaks.com/topic/147336-simple-insert-question-im-missing-somethign-easy/#findComment-773508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.