php - 解析错误:语法错误,第 29 行 D:\Xampp\htdocs\profile\new\view.php 中的意外 'if' (T_IF)
问题描述
我收到解析错误意外 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();
?>
解决方案
您收到此错误是因为您缺少一个分号;
来终止上述代码的第 4 行,即
$username = $_SESSION['username']
终止行(请参阅添加的分号),问题将得到解决。
$username = $_SESSION['username'];
推荐阅读
- c - malloc 大小的一般建议
- java - 如何在无限滚动(延迟加载)中加载所有条目以解析 Java 中的 HTML
- node.js - 我的环境变量出现未定义
- mysql - Mysql 分组行
- vue.js - 如何将 v-for 与 Range 一起使用并使用 push() 添加其他输入
- angular - 使用 ej2 网格和刷新数据源网格时出现“错误类型错误:无法读取 null 的属性‘refreshUI’”
- powerapps - PowerApps 中每个月每周的第一天
- python - 我可以使用带有迭代器参数的函数生成列表吗?
- c++ - 如何在并行编程中处理 MPI_Sendrecv 中的死锁?
- postgresql - Kubernetes pod 如何连接到与主机在同一本地网络(集群外)中运行的数据库?