我試圖從他們的個人資料中的用戶展示的帖子,我使用的當前查詢正常工作,以顯示所有人的帖子,但是當我嘗試編輯它時只顯示由用戶發佈個人資料,我就可以輸出這些錯誤:試圖獲取非對象和未定義索引錯誤的屬性PHP
注意:未定義指數:Tezma在C:\ xampppp \ htdocs中\ socialnetwork \上線62 profile_page.php
注意:嘗試在第70行獲取非對象的屬性在C:\ xampppp \ htdocs \ socialnetwork \ profile_page.php上線70
這是我到目前爲止所有的代碼:
<?php
$conn = new mysqli("localhost", "root", "", "login");
if($conn->connect_error) {
die("Connection Failed: " . $conn->connect_error);
}
$username = $_GET[$data->username]; <-- Line 62
$sql = "SELECT *
FROM posts
WHERE post_user_name = $username
ORDER BY post_date DESC";
$result = $conn->query($sql);
if($result->num_rows > 0) { <-- Line 70
while($row = $result->fetch_assoc()){
echo "<div class='well well-sm'>";
echo "<img style='float:left;margin-right:6px;box-shadow:0px 0px 1px #888;' src='user_pictures/default.jpg' width='7%'>";
echo "<span class='bold'><a href='profile.php?user=".$row['post_user_name']."'>".$row['post_user_name']."</a></span><br>";
echo "<span>".$row['post_date']."</span>";
echo "<hr style='margin-top:2px;margin-bottom:2px;'>";
echo "<p style='margin-bottom:0px;'>".$row['post_content']."</p>";
echo "</div>";
}
} else {
echo "<div class='well well-sm'>";
echo "0 Results";
echo "</div>";
}
$conn->close();
?>
什麼是62行?我看不到Tezma在您的代碼 –
62行是「$ username = $ _GET [$ data-> username];」 70 – TheTezma
行是「如果($ result-> NUM_ROWS> 0){」 – TheTezma