Hello,
Background information
I'm preparing a stock website where i want to give members the option to track their own stockpicks. A so called "watchist" or "track record".
I made a script where the member can enter the stockpick, whereafter the symbol and the price of the stock at that moment will be entered and stored into the database.
My question
When the member wants to sell the stock, he needs to fill in a form with the ticker symbol he wants to sell and then the ticker should be stored in the database with the sell price at that single moment. The sell price should be stored in the "sell" column in the database, in the same row as the bought stock (column "buy").
How shall this script look like?
Code
The table in the database is "portfolio" with rows "id", "symbol", "buy" and "sell".
This is what i have now:
<?php
if(isset($_POST['symbol'])){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s='.$_POST['symbol'].'&f=sl1d1t1c1ohgv&e=.csv' );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$contents = explode( ',', str_replace( '"', '', $output ) );
echo "<p>Stock: <b>\$$contents[1]</b> </p>";
$conn = mysql_connect("#*$!","#*$!","#*$!");
$db = mysql_select_db("#*$!",$conn);
mysql_select_db("my_db", $con);
mysql_query("UPDATE portfolio SET sell=$contents[1]
WHERE symbol=’$_POST[symbol]’");
echo “Your stock has been sold”;
mysql_close($conn);
?>