2016-07-06 68 views
-2

我試圖從他們的個人資料中的用戶展示的帖子,我使用的當前查詢正常工作,以顯示所有人的帖子,但是當我嘗試編輯它時只顯示由用戶發佈個人資料,我就可以輸出這些錯誤:試圖獲取非對象和未定義索引錯誤的屬性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(); 
    ?> 
+0

什麼是62行?我看不到Tezma在您的代碼 –

+0

62行是「$ username = $ _GET [$ data-> username];」 70 – TheTezma

+0

行是「如果($ result-> NUM_ROWS> 0){」 – TheTezma

回答

0

林不知道用線62

$username = $_GET[$data->username]; 

$ _GET [KEY]從URL中的關鍵字進行檢索值。 URL是這樣的:username=username

+0

是的,它應該是$ _GET [「用戶」],如上面的評論已經:-) – Werner

+0

URL是:socialnetwork/profile.php?user = Tezma,但在我的profile.php頁面我include_once profile_page.php這是我的大部分代碼,其中包括上面顯示的代碼,我試圖檢索用戶創建的帖子我的數據庫。 – TheTezma

+0

嘗試添加$ result-> store_result();在這裏看到第70行:http://php.net/manual/de/mysqli-result.num-rows.php – raviolican

相關問題