我尝试创建用户个人资料时,可以从网址获取ID,然后从该用户那里获取所有信息。
<?php
session_start();
$userID = $_GET["id"];
$getUserNames = "SELECT * FROM users where id=$userID";
$result = $conn->query("getUserNames");
$row = mysqli_fetch_assoc($result);
if (isset($_GET["id"])) {
echo "<h1>";
echo $row["username"];
echo "</h1>";
echo "<p><b>Name: </b>";
echo $row["username"];
echo "</p>";
echo "<p><b>Password: </b>***** (<a href='#'>Change Password</a>)</p>";
} else {
if (isset($_SESSION["username"])) {
echo "<h1>";
echo $_SESSION["username"];
echo "</h1>";
echo "<p><b>Name: </b>";
echo $_SESSION["username"];
echo "</p>";
echo "<p><b>Password: </b>***** (<a href='#'>Change Password</a>)</p>";
} else {
echo "<p>You need to be logged in too see your profile!";
}
}?>
我从回声中得不到任何错误。
请帮忙!
答案 0 :(得分:0)
$conn->query("getUserNames");
出现错误,该错误应为:$conn->query($getUserNames);
修复程序的完整新代码如下所示:
<?php
session_start();
$userID = $_GET["id"];
$getUserNames = "SELECT * FROM users where id=$userID";
$result = $conn->query($getUserNames);
$row = mysqli_fetch_assoc($result);
if (isset($_GET["id"])) {
echo "<h1>";
echo $row["username"];
echo "</h1>";
echo "<p><b>Name: </b>";
echo $row["username"];
echo "</p>";
echo "<p><b>Password: </b>***** (<a href='#'>Change Password</a>)</p>";
} else {
if (isset($_SESSION["username"])) {
echo "<h1>";
echo $_SESSION["username"];
echo "</h1>";
echo "<p><b>Name: </b>";
echo $_SESSION["username"];
echo "</p>";
echo "<p><b>Password: </b>***** (<a href='#'>Change Password</a>)</p>";
} else {
echo "<p>You need to be logged in too see your profile!";
}
}?>