我在php代码中得到解析错误代码

时间:2019-03-02 02:57:32

标签: php

我正在尝试加载我的网站,但收到错误消息:

Parse error: syntax error, unexpected '$result' (T_VARIABLE) in 
/var/www/html/dbconnect.php on line 17

有人知道第17行有什么问题吗?我似乎找不到答案

Php代码:

<?php
$servername = "localhost";
$database = "db";
$username = "root";
$password = "philip123";

// Create connection

$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, name, lastname, email FROM Students"
$result = $conn-> query($sql);

if ($result-> num_rows > 0) {
    while ($row = $result-> fetch_assoc()) {
        echo "<tr><td>". $row["id"] ."</td><td>". $row["name"] ."</td><td>".     $row["lastname"] ."</td><td>". $row["email"] ."</td></tr>";
    }
echo "</table>";
}
else {
    echo "0 results";
}

$conn-> close();


?>

第17行是此行:     $ result = $ conn->查询($ sql);

1 个答案:

答案 0 :(得分:0)

您在该行缺少分号:

$sql = "SELECT id, name, lastname, email FROM Students"