我正在尝试通过php查询在HTML页面上显示我的SQL数据库中的数据。
之前我以同样的方式完成了类似的查询,但是这个查询在我的html页面上没有显示任何结果,我不明白为什么。
<?php
$con=mysqli_connect("localhost","root","password","registration");
if (mysqli_connect_errno())
{
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
$query = "SELECT * FROM goal WHERE id = $_SESSION[userid]";
$result = mysqli_query($con, $query);
if($result == false) {
die("Query failed: ".mysqli_error($con).PHP_EOL.$query);
}
while($row = mysqli_fetch_assoc($result))
{
echo "Weight Lost:"."<p>".$row['weightlost']."</p>\n";
echo "Weight Unit:"."<p>".$row['weightunit']."</p>\n";
echo "Date set for goal to be reached:"."<p>".$row['whenby']."</p>\n";
}
mysqli_close($con);
?>