0
我有一個小型的社交網站,個人資料頁面和搜索頁面。這一切都可以正常工作,並且在菜單欄上通過profile.php?id=5
(例如)顯示用戶名和鏈接。 如何當我通過search.php
搜索的東西,它一切正常,但後來當我搜索後重新加載一個頁面,突然用戶名顯示爲'P'和鏈接去profile.php?id=p
有誰知道發生了什麼? 如果您需要更多信息,請告訴我,並提前致謝。 代碼:我搜索的東西后用戶名和ID更改
<?php
//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['search']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter name you are searching for.";
exit();
}
//database connection info
$host = ""; //server
$db = ""; //database name
$user = ""; //dabases user name
$pwd = ""; //password
//connecting to server and creating link to database
$link = mysqli_connect($host, $user, $pwd, $db);
//MYSQL search statement
$query = "SELECT * FROM users WHERE username SOUNDS LIKE '%$searchTerm%' or fname SOUNDS LIKE '%$searchTerm%' or lname SOUNDS LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
echo "<div class='searched'>Results for ";
echo $searchTerm;
echo "</div>";
/* check whethere there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .="<div class='user'><a href='profile?id=$row[id]'>";
$output .= "<img class='search_pp' src='" . $row['picture'] . "'/><br>";
$output .= "<div class='search_username'> " . $row['username'] . "</div>";
$output .= "<div class='search_full'>Full name: " . $row['fname'] . " " . $row['lname'] . "</div>";
$output .= "<div class='search_sex'>" . $row['sex'] . "</div></div></a>";
}
echo $output;
}
else
echo "No records of " . $searchTerm;
?>
這是用戶名改變爲 'P'
<?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?>
而這正是在鏈路變爲 'P'
<a href="profile?id=<?php echo htmlentities($_SESSION['user']['id'], ENT_QUOTES, 'UTF-8'); ?>">
的ID,然後用戶的用戶名和編號在整個網站中都變爲'p'