0

Update I found out that $cash is only holding a value of 1, when the database has a value of 10,942.54. the number format i was using in portfolio.php was stretching the 1 to 10,000. Any idea why the query for cash is returning 1?


I've created the portfolio page, the sell page and done all relevant query statements. After selling my stocks they are deleted correctly from the DB and the cash value is also updated correctly.

However the cash value in portfolio and sell screens remain at 10,000? even though the database states 10,914 etc.

I have no idea why the pages are not pinging the new vale.

<?php
/*Controller*/

// configuration
require("../includes/config.php"); 

// Query Database for:  
$cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);

// render portfolio, passing variables.

render("sell_form.php", ["cash" => $cash,"title" => "Sell"]);

$stock = lookup($_POST["symbol"]);

if (!empty ($_POST["symbol"]) ) 
{
    if ($stock == false)
    {
        apologize("Invalid stock name");                    
    }
else
    {   
query("UPDATE users SET cash = cash + ? WHERE id = ?", $stock["price"],$_SESSION["id"]);
query("DELETE FROM shares WHERE id = ? AND symbol = ?",$_SESSION["id"], $_POST["symbol"]);
render("sell_confirmation.php", ["stock" =>$stock,"title" => "Sale"]);
 }
}    
?>
5
  • Your code renders "sell_confirmation.php" after the sale. How are you getting back to history or sell screens? Are you just going back to them (probably still in cache in the browser), or are you taking a path that causes them to be re-rendered? Without seeing sell_confirmation or knowing how you are going back to those pages, hard to know what's going on.
    – Cliff B
    Nov 7, 2015 at 2:15
  • A "back" button is present in sell_confirmation.php's footer, it returns you to index.php (i renamed and moved files around), which is a screen with, buy,sell,portfolio,history on it - history is not yet implemented, neither is buy. once i go back to index.php after the sale I go into portfolio which should be pinging the new cash value for that user. but it still reads wrongly. - $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]); is what portfolio is doing for cash value, this should return correctly surly? Nov 7, 2015 at 2:23
  • It depends on how your back button was implemented. If it just causes the browser to go back, it's likely that it's just pulling the old version from the local cache, not rerendering. Now, if it has code to force a rerender, that's another story. Since my crystal ball is in the shop, I can't tell you what your unposted code does.
    – Cliff B
    Nov 7, 2015 at 2:31
  • fair point cliff lol heres the code ( just a html link) : <a href="index.php">Go Back</a> , how do you force the back buttons to re-render? i would of thought it would do this every time because when i go in portfolio it runs the controller, and the controller tells it to query the cash value. Nov 7, 2015 at 2:59
  • I found out the $cash is only holding a value of 1, when the database has a value of 10,942.54. the number format i was using in portfolio.php was stretching the 1 to 10,000. Any idea why the query for cash is returning 1? Nov 7, 2015 at 20:19

0

You must log in to answer this question.

Browse other questions tagged .