所以我制作了一个ScoreBoard系统,但每当我的添加/更新代码块运行时,它都会获取一个 解析错误:语法错误,持有mysqli_query()的行上的意外T_VARIABLE;如果它失败了就行,这是我的代码。
<form method="post" action="">
<center>
<font color="green">Your name Max length is 15</font>
<input type="text" name="username" maxlength="15">
<input type="submit" name="submit" value="Submit">
</center>
</form>
<font color='red'><center>
<?php
if (isset($_POST['username']))
{
$link = mysqli_connect("host","user","pass","db") or die("Error " . mysqli_error($link));
// $getname = $_POST['username'];
$getname = mysqli_real_escape_string($link,$_POST['username']);
$percentage = "10";
$querycheck = ("SELECT * from scoreboard where name = $getname")
$result = mysqli_query($link, $querycheck);
if (mysql_num_rows($querycheck) > 0)
{
$queryexist = ("UPDATE scoreboard set percentage = 20 where name = $getname");
$resultexist = mysqli_query($link, $queryexist);
echo "<center><font color='green' size='2'>Your score has been updated successfuly</font></center>";
}
else
{
$querydoesnt = ("INSERT INTO scoreboard (name,percent) VALUES ('$getname',$percentage)");
echo "<center><font color='green' size='2'>Your name has been added to the scoreboard successfuly </font></center>!";
}
?>
</font></center>
它给我一个错误,显然我的mysqli_query行有问题,但第一个错误。
答案 0 :(得分:1)
我想你忘记了那行上的分号
$querycheck = ("SELECT * from scoreboard where name = $getname");
^
HERE
答案 1 :(得分:1)
$querycheck = ("SELECT * from scoreboard where name = $getname") ;
忘了加分号
答案 2 :(得分:1)
您忘记添加分号;
,但忘记结束if statement
$querycheck = ("SELECT * from scoreboard where name = $getname");
^^^^
每个PHP语句都以分号(;
)结尾。 PHP不会停止读取语句,直到它达到分号。如果在行的末尾省略分号,PHP将继续阅读该语句。它将两行作为一个语句读取,因此它会报错,例如Parse error: parse error in
...
// if statement block
<font color='red'><center>
<?php
if (isset($_POST['username']))
{
// your code
}
</font></center>
注意强>
您正在使用mysqli_
语句,因此您需要将mysql_num_rows()
更改为mysqli_num_rows()
if (mysqli_num_rows($querycheck) > 0) {
// your code
}