Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
i think this is an easy insert question
Old 02-28-2009, 02:31 PM i think this is an easy insert question
Novice Talker

Posts: 14
Name: biklad
Trades: 0
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
jcrensha627 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-28-2009, 03:59 PM Re: i think this is an easy insert question
Corey's Avatar
Super Talker

Latest Blog Post:
Pre-Pop Offers
Posts: 142
Name: Corey
Location: United States
Trades: 0
Try:
PHP Code:
$insert mysql_query("INSERT INTO `trades` VALUES ('NULL', 'JAME', '" $_POST['quantity'] . "', '" $total_cost "')"
__________________

Please login or register to view this content. Registration is FREE

Phone: 888-400-4359 || AIM S/N: CoreyPeerFly
Launched in 2008 - Daily Payments by PayPal
Corey is offline
Reply With Quote
View Public Profile Visit Corey's homepage!
 
Reply     « Reply to i think this is an easy insert question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15391 seconds with 12 queries