在代码中添加 $post_id 变量<iframe>



我有这个代码:

<iframe src="http://voting.first-jump.com/init.php?a=g&g=1516932783462&m=1&n=5&s=64&f=3.png&f_a=&f_b=&f_c=" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" frameborder="0" height="84" scrolling="no" width="323"></iframe>

我在 src 字符串中添加了一个 $post_id(为一个人在我的社交网络上发布的每个帖子制作唯一的帧加载(,所以,现在它是这样的:

<iframe src="http://voting.first-jump.com/init.php?a=g&g=1516932126956&m=10&n=5&s=20&f=3.png&f_a=&f_b=&f_c= <?php echo $post_id; ?>" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" frameborder="0" height="33" scrolling="no" width="103"></iframe>

我不知道我做错了什么,因为 $post_id 不起作用。

谢谢!

编辑:这是孔 php 代码:

<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>
<body>
    <style type="text/css">
    * {
        font-size: 12px;
        font-family: Arial, Helvetica, Sans-serif;
    }
    </style>
    <?php  
    require 'config/config.php';
    include("includes/classes/User.php");
    include("includes/classes/Post.php");
    include("includes/classes/Notification.php");
    if (isset($_SESSION['username'])) {
        $userLoggedIn = $_SESSION['username'];
        $user_details_query = mysqli_query($con, "SELECT * FROM users WHERE username='$userLoggedIn'");
        $user = mysqli_fetch_array($user_details_query);
    }
    else {
        header("Location: register.php");
    }
    ?>

    <script>
        function toggle() {
            var element = document.getElementById("comment_section");
            if(element.style.display == "block") 
                element.style.display = "none";
            else 
                element.style.display = "block";
        }
    </script>
    <?php  
    //Get id of post
    if(isset($_GET['post_id'])) {
        $post_id = $_GET['post_id'];
    }
    $user_query = mysqli_query($con, "SELECT added_by, user_to FROM posts WHERE id='$post_id'");
    $row = mysqli_fetch_array($user_query);
    $posted_to = $row['added_by'];
    $user_to = $row['user_to'];


    if(isset($_POST['postComment' . $post_id])) {
        $post_body = $_POST['post_body'];
        $post_body = mysqli_escape_string($con, $post_body);
        $date_time_now = date("Y-m-d H:i:s");
        $insert_post = mysqli_query($con, "INSERT INTO comments VALUES ('', '$post_body', '$userLoggedIn', '$posted_to', '$date_time_now', 'no', '$post_id')");

if($posted_to != $userLoggedIn) {
            $notification = new Notification($con, $userLoggedIn);
            $notification->insertNotification($post_id, $posted_to, "comment");
        }
        if($user_to != 'none' && $user_to != $userLoggedIn) {
            $notification = new Notification($con, $userLoggedIn);
            $notification->insertNotification($post_id, $user_to, "profile_comment");
        }

        $get_commenters = mysqli_query($con, "SELECT * FROM comments WHERE post_id='$post_id'");
        $notified_users = array();
        while($row = mysqli_fetch_array($get_commenters)) {
            if($row['posted_by'] != $posted_to && $row['posted_by'] != $user_to 
                && $row['posted_by'] != $userLoggedIn && !in_array($row['posted_by'], $notified_users)) {
                $notification = new Notification($con, $userLoggedIn);
                $notification->insertNotification($post_id, $row['posted_by'], "comment_non_owner");
                array_push($notified_users, $row['posted_by']);
            }
        }
        echo "<p>Comment Posted </p>";
    }
    ?>
    <form action="comment_frame.php?post_id=<?php echo $post_id; ?>" id="comment_form" name="postComment<?php echo $post_id; ?>" method="POST">
        <textarea name="post_body"></textarea>
        <input type="submit" name="postComment<?php echo $post_id; ?>" value="Post">    

    </form>
<iframe src="http://voting.first-jump.com/init.php?a=g&g=1516932126956&m=10&n=5&s=20&f=3.png&f_a=&f_b=&f_c= <?php echo $post_id; ?>" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" frameborder="0" height="33" scrolling="no" width="103"></iframe>











    <!-- Load comments -->
    <?php  
    $get_comments = mysqli_query($con, "SELECT * FROM comments WHERE post_id='$post_id' ORDER BY id ASC");
    $count = mysqli_num_rows($get_comments);
    if($count != 0) {
        while($comment = mysqli_fetch_array($get_comments)) {
            $comment_body = $comment['post_body'];
            $posted_to = $comment['posted_to'];
            $posted_by = $comment['posted_by'];
            $date_added = $comment['date_added'];
            $removed = $comment['removed'];
            //Timeframe
            $date_time_now = date("Y-m-d H:i:s");
            $start_date = new DateTime($date_added); //Time of post
            $end_date = new DateTime($date_time_now); //Current time
            $interval = $start_date->diff($end_date); //Difference between dates 
            if($interval->y >= 1) {
                if($interval == 1)
                    $time_message = $interval->y . " year ago"; //1 year ago
                else 
                    $time_message = $interval->y . " years ago"; //1+ year ago
            }
            else if ($interval->m >= 1) {
                if($interval->d == 0) {
                    $days = " ago";
                }
                else if($interval->d == 1) {
                    $days = $interval->d . " day ago";
                }
                else {
                    $days = $interval->d . " days ago";
                }

                if($interval->m == 1) {
                    $time_message = $interval->m . " month". $days;
                }
                else {
                    $time_message = $interval->m . " months". $days;
                }
            }
            else if($interval->d >= 1) {
                if($interval->d == 1) {
                    $time_message = "Yesterday";
                }
                else {
                    $time_message = $interval->d . " days ago";
                }
            }
            else if($interval->h >= 1) {
                if($interval->h == 1) {
                    $time_message = $interval->h . " hour ago";
                }
                else {
                    $time_message = $interval->h . " hours ago";
                }
            }
            else if($interval->i >= 1) {
                if($interval->i == 1) {
                    $time_message = $interval->i . " minute ago";
                }
                else {
                    $time_message = $interval->i . " minutes ago";
                }
            }
            else {
                if($interval->s < 30) {
                    $time_message = "Just now";
                }
                else {
                    $time_message = $interval->s . " seconds ago";
                }
            }
            $user_obj = new User($con, $posted_by);

            ?>
            <div class="comment_section">
                <a href="<?php echo $posted_by?>" target="_parent"><img src="<?php echo $user_obj->getProfilePic();?>" title="<?php echo $posted_by; ?>" style="float:left;" height="30"></a>
                <a href="<?php echo $posted_by?>" target="_parent"> <b> <?php echo $user_obj->getFirstAndLastName(); ?> </b></a>
                &nbsp;&nbsp;&nbsp;&nbsp; <?php echo $time_message . "<br>" . $comment_body; ?> 
                <hr>

            </div>
            <?php
        }
    }
    else {
        echo "<center><br><br>No reviews</center>";
    }
    ?>



</body>
</html>

代码之间有空格。

这是你的错误

f_c= <?php echo $post_id; ?> .该空间将在 url 中转换为%20

所以它看起来像这样。 f_c=%20<?php echo $post_id; ?>

你可以试试这个

<iframe src="http://voting.first-jump.com/init.php?a=g&g=1516932126956&m=10&n=5&s=20&f=3.png&f_a=&f_b=&f_c=<?php echo $post_id; ?>" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" frameborder="0" height="33" scrolling="no" width="103"></iframe>

最新更新