1

所以我做了一个记分板系统,但是每当我的添加/更新代码块运行时,它都会给我一个解析错误:语法错误,包含 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 行有问题,虽然是第一个。

4

3 回答 3

1

我想你在那条线上忘记了一个分号

$querycheck = ("SELECT * from scoreboard where name = $getname");
                                                                ^
                                                               HERE
于 2013-10-04T05:11:27.997 回答
1
$querycheck = ("SELECT * from scoreboard where name = $getname") ;

忘了放分号

于 2013-10-04T05:11:29.383 回答
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
}
于 2013-10-04T05:19:04.943 回答