I've got everything working for pset7 except for buy.php, it works fine other than allowing users to buy shares they can't afford. I can't figure out why this bit of code isn't working:

  // get users cash
    $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
    // calculate value
    $value = $stock["price"] * $_POST["shares"];

    // if cash less than value
    if ($cash < $value)
        apologize("Insufficient funds.");

$cash isn't really what you need. query() returns an array of matched rows. If you tried to dump($cash), you'd find that $cash itself isn't the integer value, but rather an array that contains another array inside of which is a key named "cash". To access this value, you should have something like


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .