0

I checked all of my code in sell.php and when I try to run it I get the syntax error of unexpected 'if' in /home/...../sell.php. Can anybody try to find my mistake. Part of my code is below.

if ($stock === false)
    {
        apologize("Entered stock symbol was invalid.");
    }
    else
    {
        $rows = query("SELECT shares FROM shares WHERE user_id = ? and symbol = ?", $_SESSION["id"], strtoupper($_POST["code"]))

        if (count($rows) == 1)
        {
            $shares = $rows[0]["shares"];
        }
        else
        {
            apologize("Shares for specified symbol not found.");
        }

1 Answer 1

0

This is a syntax error, or in other words, the code is not following the rules of PHP. When PHP says unexpected if, it doesn't necessarily mean the if statement itself is incorrect, it can also mean that something before the statement is not correct.

For example, suppose the error is indicated at this line:

if (count($rows) == 1)

This looks fine, so to locate the actual culprit we look at the line before it:

$rows = query("SELECT shares FROM shares WHERE user_id = ? and symbol = ?", $_SESSION["id"], strtoupper($_POST["code"]))

Looks mostly fine, except it's missing the all important semi-colon ;.

According the PHP Manual:

As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement.

1
  • Yup and that did it! Thanks! Commented Aug 25, 2014 at 19:23

You must log in to answer this question.

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