mitzter Posted May 23, 2012 Share Posted May 23, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/262981-update-variable-in-database-with-php/ Share on other sites More sharing options...
trq Posted May 23, 2012 Share Posted May 23, 2012 Sorry, what exactly is the issue? Quote Link to comment https://forums.phpfreaks.com/topic/262981-update-variable-in-database-with-php/#findComment-1347888 Share on other sites More sharing options...
mitzter Posted May 23, 2012 Author Share Posted May 23, 2012 Oh sorry, the script doesn't work and i would like to know what i did wrong here... Quote Link to comment https://forums.phpfreaks.com/topic/262981-update-variable-in-database-with-php/#findComment-1347894 Share on other sites More sharing options...
trq Posted May 23, 2012 Share Posted May 23, 2012 Which part doesn't work? Are you getting errors? You should be. For starters, this line: echo “Your stock has been sold”; Will produce a fatal error because of those quotes. Have you got error reporting enabled while developing? Your going to need to provide more detail if you expect help. Quote Link to comment https://forums.phpfreaks.com/topic/262981-update-variable-in-database-with-php/#findComment-1347900 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.