-2

Im trying to have posts from a user show on their profile, the current query I'm using worked fine for showing posts by everyone but when I try to edit it to only show posts by the users profile I am on it outputs these errors:

Notice: Undefined index: Tezma in C:\xampppp\htdocs\socialnetwork\profile_page.php on line 62

Notice: Trying to get property of non-object in C:\xampppp\htdocs\socialnetwork\profile_page.php on line 70

This is all the code that I have so far:

<?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();
    ?>
TheTezma
  • 17
  • 3

1 Answers1

0

Im not sure with line 62

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

$_GET[KEY] is retrieving value from key in the URL. Does the URL look like :username=username

raviolican
  • 362
  • 4
  • 14
  • Yep, it should be $_GET['user'], as commented above already :-) – Werner Jul 06 '16 at 16:05
  • the URL is: socialnetwork/profile.php?user=Tezma but on my profile.php page I include_once profile_page.php which is where majority of my code it including the code shown above, I am trying to retrieve posts created by the user from my database. – TheTezma Jul 06 '16 at 16:07
  • try and add add $result->store_result(); before line 70 seen here:http://php.net/manual/de/mysqli-result.num-rows.php – raviolican Jul 06 '16 at 16:20