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
https://forums.phpfreaks.com/topic/262981-update-variable-in-database-with-php/
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.

 

Archived

This topic is now archived and is closed to further replies.

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