if ($_POST['sendRequest'] == "savetodb") {
// Access the value of the dynamic text field variable sent from flash
$Full_Name = $_POST['Full_Name'];
$SharesPur = $_POST['purchase_shares'];
include_once "connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM stock_index WHERE Full_Name='$Full_Name'");
while($row = mysql_fetch_array($sql)) {
$Industry = $row["Industry"];
$Symbol = $row["Symbol"];
$Movement = $row["Movement"];
$Shares = $row["Shares"];
$Share_Volume = $row["Share_Volume"];
$Starting_Value = $row["Starting_Value"];
$Current_Value = $row["Current_Value"];
$Total_Cost = $Current_Value * $Shares;
$sql1 = mysql_query("SELECT * FROM userreg WHERE id='$id'");
while($row = mysql_fetch_array($sql1)) {
$id = $row["id"];
$username = $row["username"];
$networth = $row["networth"];
$calculate_balance = $networth-$Total_Cost;
$remaining_balance = number_format($calculate_balance);
if ($networth < $Total_Cost) {
print "errorMsg=success_no";
} else {
$query = "UPDATE userreg SET networth = '$calculate_balance' WHERE id='$id'";
mysql_query($query);
$sql2 = mysql_query("INSERT INTO portfolio (username, userid, Full_Name, Symbol, Shares, Bought_At, Starting_Value, Current_Value, Share_Volume, Movement, Industry, open_date)
VALUES('$username','$id','$Full_Name','$Symbol','$SharesPur','$Current_Value','$Starting_Value','$Current_Value', '$Share_Volume','$Movement','$Industry', now())")
or die (mysql_error());
}
}
}
}
|