PHP / SQL奇怪的输出

时间:2018-04-24 20:31:01

标签: php sql

你好,因为某些原因,当我运行actionpage11.php时,我得到一个非常奇怪的输出,如下所示,我似乎无法找出原因。我想知道是否有人知道为什么会这样?

输出:

enter image description here

userprofile.php:

<?php

    session_start();
    require 'config.php';


    $id = $_POST['bidder_id'];
    $sql = "SELECT * FROM `customer` WHERE email_adress = '$id'";
    $sql2 = "SELECT * FROM `review` WHERE accepted_bidder = '$id'";
    $sql3 = "SELECT * FROM `comment` WHERE comment_to = '$id';";

    $result = $conn->query($sql);
    $result2 = $conn->query($sql2);
    $result3 = $conn->query($sql3);


    ?>
    <!DOCTYPE html>
    <html lang="en">


            <!-- PAGE CONTENT -->
            <div class="page-content page-search-result">
                <div class="container">
                <table>
                    <tr>
                        <th>Name</th>
                        <th>Description</th>
                        <th>Skill</th>

                    </tr>

          <!-- populate table from mysql database -->
                    <?php while($row = mysqli_fetch_array($result)):?>
                    <tr>

                        <td><?php echo $row['name']; ?></td>
                        <td><?php echo $row['description'];?></td>
                        <td><?php echo $row['skill'];?></td>

                    </tr>
                    <?php endwhile;?>
                </table>

                    <!-- End Search Form -->

                </div>
            </div>

            <div class="page-content page-search-result">
                <div class="container">
                <table>
                    <tr>
                        <th>review</th>
                        <th>score</th>


                    </tr>

          <!-- populate table from mysql database -->
                    <?php while($row = mysqli_fetch_array($result2)):?>
                    <tr>

                        <td><?php echo $row['review_description']; ?></td>
                        <td><?php echo $row['rating'];?>/10</td>

                    </tr>
                    <?php endwhile;?>
                </table>
                        <form action="actionpage11.php" method="POST" style="border:1px solid #ccc">
                        <div class="container">

                        <input type="hidden" value="<?php echo $id; ?>" name="comment_to" />        


                        <label><b>Comment</b></label>
                        <input type="text" placeholder="Enter Comment" name="comment" >

                        <div class="clearfix">
                        <button type="submit" class="signupbtn" name="submit" value="submit">Submit</button>
                </form>
            </div>
                    <?php while($row = mysqli_fetch_array($result3)):?>
                    <tr>

                        <td><?php echo $row['comment']; ?></td>
                        <td><?php echo $row['comment_by']; ?></td>
                        <td><?php echo $row['comment_time']; ?></td>


                    </tr>
                    <?php endwhile;?>

                    <!-- End Search Form -->

                </div>
            </div>
            <!-- END PAGE CONTENT -->

actionpage11.php:

<?php
session_start();

require 'config.php';


<?php
session_start();

require 'config.php';


$comment    = $_POST['comment'];
$comment_to    = $_POST['comment_to'];
$comment_by = $_SESSION['login_user'];


$query   = "INSERT into `comment` (comment,comment_time,comment_by,comment_to) VALUES('" . $comment . "',now(),'" . $comment_by . "','" . $comment_to . "')";

$success = $conn->query($query);

if (!$success) {
    die("Couldn't enter data: ".$conn->error);

}

 header("location: userprofile.php");
$conn->close();

?>

2 个答案:

答案 0 :(得分:1)

actionpage11.php结束时,它确实:

header("Location: userprofile.php");

当重定向到userprofile.php时,没有POST个参数(重定向始终使用GET,而不是POST),因此$_POST['bidder_id']赢了#t}设定。

如果通常在登录页面设置userprofile.php,则可以将其放入会话变量中。然后在所有其余页面中使用它,而不是使用$_POST

或许您应该重定向到格式为userprofile.php的网页,而不是直接重定向到userprofile.php

答案 1 :(得分:0)

$_POST['bidder_id']未设置。可能$_GET['bidder_id']$_POST['bidder_id']不是。