Jump to content

Update $variable in database with php


mitzter

Recommended Posts

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);

?>

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.