gpt4 book ai didi

php - 解析错误: parse error in php

转载 作者:行者123 更新时间:2023-11-29 07:30:56 26 4
gpt4 key购买 nike

我有这个 php 代码,可以访问用户和投资组合表

但是我一直遇到解析错误:第 28 行/Users/...../Sites/..../sell.php 中的解析错误

如果有人能帮助我,那就太好了。

<?
// 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");
}
}
?>

最佳答案

这个else是从哪里来的?添加}:

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

您的最终代码将是:

<?

// 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");

}

?>

关于php - 解析错误: parse error in php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32678032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com