试图获得非对象和财产的财产未定义的索引错误PHP

时间:2016-07-06 15:53:28

标签: php

我试图在他们的个人资料中显示来自用户节目的帖子,我使用的当前查询工作正常以显示所有人的帖子但是当我尝试编辑它时仅显示用户个人资料的帖子我在它会输出这些错误:

注意:未定义的索引:第62行的C:\ xampppp \ htdocs \ socialnetwork \ profile_page.php中的Tezma

注意:尝试在第70行的C:\ xampppp \ htdocs \ socialnetwork \ profile_page.php中获取非对象的属性

这是我到目前为止的所有代码:

<?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();
    ?>

1 个答案:

答案 0 :(得分:0)

我不确定第62行

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

$ _ GET [KEY]正在从URL中的key中检索值。该网址是否为:username=username