ParseError语法错误,意外'while'(T_WHILE)

时间:2018-01-02 07:25:46

标签: php

<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "jaka_crud_ci";

mysqli_connect($server, $username, $password, $database);

$query = "SELECT * FROM pembeli";
$result = mysqli_query($query)

while ( $buyer = mysqli_fetch_assoc($result)){
echo $buyer ["nama_pembeli"];
echo $buyer ["nama_barang"];
echo $buyer ["nama_retribusi"];
}
?>

上面的代码显示语法错误,意外'while'(T_WHILE)。如何摆脱错误?帮帮我

4 个答案:

答案 0 :(得分:2)

请在下面更新

$result = mysqli_query($query)

$result = mysqli_query($query);
该行中缺少

;。这就是错误发生的原因。

答案 1 :(得分:2)

;后您遗失mysqli_query($query)。更新后的代码如下。

 <?php
    $server = "localhost";
    $username = "root";
    $password = "";
    $database = "jaka_crud_ci";

    mysqli_connect($server, $username, $password, $database);

    $query = "SELECT * FROM pembeli";
    $result = mysqli_query($query);

    while ( $buyer = mysqli_fetch_assoc($result)){
    echo $buyer ["nama_pembeli"];
    echo $buyer ["nama_barang"];
    echo $buyer ["nama_retribusi"];
    }
    ?>

答案 2 :(得分:1)

的末尾添加分号
$result = mysqli_query($query);

你知道mysqli_query的语法错误,正确的是, mysqli_query($ connection_variable,$ query)

所以对于你的情况来说就像是,

$con = mysqli_connect($server, $username, $password, $database);

然后使用它,

$result = mysqli_query($con, $query);

答案 3 :(得分:0)

它非常简单的语法错误,你错过了;在mysqli_query($ query)之后

您还可以使用php命令行选项检查sytax错误

php -l filename 

-l Provides a convenient way to perform only a syntax check on the given PHP code. On success, the text No syntax errors detected in <filename> is written to standard output

它将显示给定文件名中是否存在任何sytax错误

更多详情:http://php.net/manual/en/features.commandline.options.php

我希望这很有用