循环时,Echo在php中不工作

循环时,Echo在php中不工作,php,Php,更新代码问题----- 现在它应该可以与此代码一起使用。我在评论中解释了错误的部分: <?php require "conn.php"; require "header.php"; if (isset($_GET["id"])) { // all the below code is happening only when $_GET["id"] is defined $id = mysqli_real_escape_string($conn,$_GET["id"]); //this

更新代码问题-----


现在它应该可以与此代码一起使用。我在评论中解释了错误的部分:

<?php
require "conn.php";
require "header.php";
if (isset($_GET["id"])) { // all the below code is happening only when $_GET["id"] is defined
    $id = mysqli_real_escape_string($conn,$_GET["id"]); //this won't protect you from sql injections...
    $myid = $_SESSION["USER"]; //

    $image = "<img src='showimage.php?id=".$id." class='img-responsive img-circle margin' style='display:inline' alt='Bird' width='350' height='350'>";

    $query = "SELECT * FROM register WHERE id='".$id."'";
    $result = mysqli_query($conn,$query);
    while ($row = mysqli_fetch_assoc($result)) {
        $firstname = $row["firstname"];
        $lastname = $row["lastname"];
        $status = $row["status"];
        $bio = $row["bio"];
    }

    if ($id == $myid) {
        $centertext = "<center><font color='black'> You cannot add yourself as your friend</font></center>"; //echo this variable somewhere you want
    } else {
        $aquery = "SELECT * FROM friends WHERE user_id='".$myid."'";
        $aresult = mysqli_query($conn,$aquery);
        while ($arow = mysqli_fetch_assoc($aresult)) {
            $friend_id = $arow["friend_id"];
            $user_id = $arow["user_id"];
            $db_userid = $arow["id"];

            // Making a query for fetch friends data
            $bquery = "SELECT * FROM friends WHERE friend_id='".$id."'"; // make first ' then " then the variable and then " and ' this is for preventing sql-injections
            $bresult = mysqli_query($conn,$bquery);
            $count = mysqli_num_rows($bresult);
            if ($count !== 0) { // =! will not check if $count is not 0 you have to change it to !==
                $cquery = "SELECT * FROM friends WHERE status=1"; // leave the '' out here, cause otherwise it's handled as a string, now its a int
                $cresult = mysqli_query($conn,$cquery);
                while ($crow = mysqli_fetch_assoc($cresult)) {
                    $status = $crow["status"];
                    if ($status == 0) {
                        $statusAlreadySent = "Your friend request has already been sent";
                    } else {
                        $statusFriends = "You are friends";
                    }
                }
            } else {
                $noFriendsYet = "You have to send him friend request";
            }

        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Theme Made By www.w3schools.com - No Copyright -->
    <title>Profile</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        body {
            font: 20px Montserrat, sans-serif;
            line-height: 1.8;
            color: #f5f6f7;
        }
        p {font-size: 16px;}
        .margin {margin-bottom: 45px;}
        .bg-1 {
            background-color: #1abc9c; /* Green */
            color: #ffffff;
        }
        .bg-2 {
            background-color: #474e5d; /* Dark Blue */
            color: #ffffff;
        }
        .bg-3 {
            background-color: #ffffff; /* White */
            color: #555555;
        }
        .bg-4 {
            background-color: #2f2f2f; /* Black Gray */
            color: #fff;
        }
    </style>
</head>
<body>

<div class="container-fluid bg-1 text-center">
    <h3 class="margin"><?php if (isset($firstname)) {echo $firstname;} elseif (isset($lastname)) {echo $lastname;}  ?></h3>
    <?php
    if (isset($image)) {echo $image;} // maybe you have to change this to if (isset($image)) {$image;}
    ?>
    <h3 class="margin">Status: <?php if (isset($statusAlreadySent)) {echo $statusAlreadySent;} elseif (isset($statusFriends)) {echo $statusFriends;} elseif (isset($noFriendsYet)) {echo $noFriendsYet;} else {echo "No status"; }?></h3> 
    <br>
</div>
<!--here comes the $centertext from above-->
<?php
    if (isset($centertext)) {echo $centertext;};
?>

<!-- Second Container -->
<div class="container-fluid bg-2 text-center">
    <h3 class="margin">About <?php if (isset($firstname)) {echo $firstname;} ?></h3>
    <p><?php if (isset($bio)) {echo $bio;};  ?></p>
</div>

<!-- Third Container (Grid) -->
<div class="container-fluid bg-3 text-center">
    <h3 class="margin"> <?php if (isset($firstname)) {echo $firstname . "friends";} ?></h3><br>
    <div class="row">
        <div class="col-sm-4">
            <p></p>
            <img src="birds1.jpg" class="img-responsive margin" style="width:100%" alt="Image">
        </div>
    </div>
</div>

<!-- Footer -->
<footer class="container-fluid bg-4 text-center">
    <p>FriendsLogin</p>
</footer>

</body>
</html>

轮廓
身体{
字体:20px蒙特塞拉特,无衬线;
线高:1.8;
颜色:#f5f6f7;
}
p{字体大小:16px;}
.margin{margin bottom:45px;}
.bg-1{
背景色:#1abc9c;/*绿色*/
颜色:#ffffff;
}
.bg-2{
背景色:#474e5d;/*深蓝色*/
颜色:#ffffff;
}
.bg-3{
背景色:#ffffff;/*白色*/
颜色:#555555;
}
.bg-4{
背景色:#2f;/*黑灰色*/
颜色:#fff;
}
地位:

关于


友谊素


检查您的
}
在htmli之前制作所有php代码,我会帮您更正,但什么时候可以that@VivekShukla5分钟后,我会发布一个回复。当我回复它时,它实际上不起作用,然后它向我显示你是朋友。你的朋友请求已经同时发送了。你能发布你的照片吗页或者有一个我能看到的实时系统?不是现在而是tomorrow@VivekShukla好吧,随你怎么说。。。但是明天我就没有时间了。。只需在你的问题中部署一个映像,我将在周五查看它。我再次添加代码,你可以看到它是在{更新的代码问题…}之后。我的数据库是这样的id(自动递增)、用户id(发送好友请求的用户)、好友id(向其发送好友请求的用户)、状态(0表示好友请求挂起,1表示好友请求已被接受)