sql >> Databáze >  >> RDS >> Mysql

Chyba analýzy:chyba analýzy v php

Odkud je toto else přichází? Přidejte } :

} else if(($shares = mysql_query($sharesQuery)) == false)

Váš konečný kód bude:

<?

    // require common code
    require_once("includes/common.php");

    //check for errors
    $error = false;
    if (isset($_POST["submit"])) {

        if (empty($_POST["symbol"])) {
            $error   = true;
            $message = "Enter a name";
        }

        else if (empty($_POST["shares"])) {
            $error   = true;
            $message = "Enter the shares";
        }

        // check if user has the stocks and the shares
        $id     = $_SESSION["id"];
        $symbol = $_POST["symbol"];

        $sharesQuery = "SELECT shares FROM portfolio WHERE id = $id AND symbol = '$symbol' ";
    } else if (($shares = mysql_query($sharesQuery)) == false) {
        $error   = true;
        $message = "Don't have the stock";
    }

    // else, if everything checks out, delete it and increment the cash

    else {
        $deleteQuery = "DELETE from portfolio WHERE id = $id AND symbol = '$symbol'";
        mysql_query($deleteQuery);

        $incrementQuery = "UPDATE users SET cash = cash + ($shares * lookup($symbol)->price) WHERE id = $id ";
        mysql_query($incrementQuery);

        //set the variables into session  and then redicrect to sell2
        $_SESSION["symbol"] = $_POST["symbol"];
        $_SESSION["shares"] = $_POST["shares"];
        redirect("sell2.php");

    }

?>


  1. Proč primární klíč nemůže obsahovat hodnoty null?

  2. Jak vypsat všechny pohledy v databázi Oracle

  3. Zmírnění fragmentace indexu

  4. Opravit chybovou zprávu 4151 „Typ prvního argumentu pro NULLIF nemůže být konstanta NULL, protože typ prvního argumentu musí být znám“ v SQL Server