Jump to content

mitzter

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mitzter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Oh sorry, the script doesn't work and i would like to know what i did wrong here...
  2. 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); ?>
  3. Thanks for your answer. In place of getCSV i made it with cURL and some adjustments. In short what i want to have the code done: I want that someone can put a ticker symbol in the form (see 1st post) and then the ticker + last price of that ticker get posted into my database. With the form the user can post the ticker, but the last price would not go thru the form but automatic. So input = ticker and output = ticker + last price I now have the following code, but it doesn't work. The basis is correct, but i've done somethind wrong. Can someone please help me with the script to get it work? <?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>AAPL stock: <b>\$$contents[1]</b> ( $contents[4] )</p>"; $conn = mysql_connect("xxx","xxx","xxx"); $db = mysql_select_db("xxx",$conn); $sql="INSERT INTO portfolio (symbol) VALUES ('$_POST[\'symbol\']')"; if (!mysql_query($sql,$conn)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($conn); } else { echo ' <form action="portfolio/insert_buy.php" method="post"> Symbol: <input type="text" name="symbol"><br /> <input type="submit" value=" Submit"> </form>'; } ?>
  4. Hello, I wrote a script where i can enter a stock symbol and it get saved in my database. This works, but when i enter the stock symbol i would like to also get the current stock price get saved into the database. The link for the stock price (i.e. AAPL): http://quote.yahoo.com/d/quotes.csv?s=AAPL&f=l1&e=.csv How do i programm this in the script below? Besides above, notice that "AAPL" in the link above has to be a varaible, which changes where i for example type in "GS". Form: PHP-script I hope someone can help me out, thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.