解析错误:语法错误,第29行的D:\ Xampp \ htdocs \ profile \ new \ view.php中出现意外的'if'(T_IF)

时间:2019-03-08 10:45:05

标签: php mysql

我收到了解析错误意外的IF(T_IF)。请帮助我更正我的代码 我在标签之前有session_start(),并使用会话用户名从数据库中选择行。请帮助我,我的代码无法正常工作

PHP代码

<?php
// connect to the database
include('connect-db.php');
$username = $_SESSION['username']
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM user WHERE username = '$username'"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";

// set table headers
echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>";

while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->id . "</td>";
echo "<td>" . $row->firstname . "</td>";
echo "<td>" . $row->lastname . "</td>";
echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
echo "</tr>";
}

echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}

// close database connection
$mysqli->close();

?>

1 个答案:

答案 0 :(得分:2)

您收到此错误,是因为缺少分号;以终止上述代码的第4行的行,即

$username = $_SESSION['username']

像这样终止行(请参阅添加的分号),问题将得到解决。

$username = $_SESSION['username'];