PHP保护访问集会话中的页面

时间:2014-04-22 10:28:47

标签: php

<?php
ob_start();
session_start();
include 'Connection.php';
$username = $_SESSION['user'];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Home Page</title>
    <meta charset="utf-8" />
    <link href="../css/my_design.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="../css/homepage.css" media="screen" rel="stylesheet" type="text/css"/>
    <link href="../css/bootstrap.css" media="screen" rel="stylesheet" type="text/css"/>
</head>

<div id="wrapper">

    <body>

        <!-- header row -->
        <div class="grid10 first">
            <?php
            include 'Header.php';
            ?>
        </div>
        <!-- 2 column row - content and navigation columns -->

        <div class="grid10 first">
            <div class="container">

                <?php

                include 'navigation.php';
                ?>

            </div>
        </div>

        <div class="grid10 first">
            <div class="container" align="center">

                <?php

                if (isset($_SESSION["user"])) {
                    echo "<table border='10' align = 'center' cellpadding='2' width = 600px height = 50px>

            <tr>
            <th>User ID</th>
            <th>Username</th>
            <th>Password</th>
            <th>email</th>
            </tr>";

                    echo "You are logged in as " . $_SESSION['user'];

                    $query = "(SELECT * FROM Users WHERE username = " . $username  . ")";

                    $result = mysqli_query($connection, $query) or die("error in the query : $query " . mysqli_error());

                    while ($row = mysqli_fetch_assoc( $result)) {

                        echo "<tr>";

                        echo "<td>" . $row['userid'] . "</td>";

                        echo "<td>" . $row['username'] . "</td>";

                        echo "<td>" . $row['password'] . "</td>";

                        echo "<td>" . $row['email'] . "</td>";

                        echo "</tr>";


                    }

                    echo "</br>Hi: ".$row['userid'];

                } else {

                    echo 'Accessed Denied';

                }
echo "</table>";

                echo "</br>";
                echo "</br>";
                echo "</br>";
                echo "</br>";
        ?>

            

        <div class="grid9 first">
            <footer id="footer">

                <?php

                include 'Footer.php';
                ?>

            </footer>
        </div>

    </body>
</div>

我每次尝试时都会收到此消息

警告:mysqli_error()预计在第60行/study/comp/c3358011/webpages/ISD/Assessment/Pages/protectedpage.php中给出1个参数0 查询中的错误:(SELECT * FROM Users WHERE username = mantis)

1 个答案:

答案 0 :(得分:0)

尝试此选择查询并将此查询替换为此 -

$query = "SELECT * FROM Users WHERE username = '".$username."'";