-1

我尝试显示用户登录到我想添加其他成员的 memberadd.php,但是,它不显示,而是空白。我同时发布了成员添加代码和登录代码,这与 memberadd php 没有从其他文件接收到变量有关吗?

这是会员添加代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/chtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="Web Programming :: Assignment 2" />
    <meta name="Keywords" content="Web, programming" />
    <title>Member Login</title>
</head>

<body>
    <h1>My Member System</h1>

</body>
</html>

<?php
session_start();
require_once('sqlconnect.inc.php');

if(isset($_SESSION['membername']))
    {
    echo "<p>Welcome back". "<br />".$_SESSION['membername']."</p>";

$conn = @mysqli_connect($host, 
        $user, 
        $pswd, 
        $dbnm);

    if (!$conn) {
        echo "<p>Database connection failure</p>"; 
    } else {

    @mysqli_select_db($conn, $dbnm)
        or die ("Database not available");
    }

    $query = "SELECT member_name FROM team";
    $result = mysqli_query($conn, $query);

    if(!$result) {
        echo "<p>Error with: ", $query, "</p>";
        } else {
        echo "<table width='10%' border='1'>";
        echo "<tr><th>Member</th></tr>";

        while ($row = mysqli_fetch_assoc($result)){
                echo "<tr>";
                echo "<td>",$row["member_name"],"</td>";
                echo "</tr>";
        }
    echo "</table>";
    mysqli_free_result($result);
    }
    }
    //
?>  

下面是登录页面

<?php
        session_start();
        require_once('sqlconnect.inc.php');

        if (isset($_POST["login"]))
        {
        $conn = @mysqli_connect($host, $user, $pswd);
                    if (!$conn) {
                    echo "<p>Database connection failure</p>"; 
                    } else {

        $selectDatabase = @mysqli_select_db($conn,$dbnm)
                    or die("<p>The database is not available.</p>");
                    }

        $email = $_POST['email'];
        $passw = $_POST['password'];

        $query = "SELECT member_email FROM team WHERE member_email = '$email' AND password = '$passw'";

        $queryResult = @mysqli_query($conn,$query)
                        or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";


        if(mysqli_num_rows($queryResult) == 0) //user is not found
        {
            header('Location: login.php');
        }else{

        if(mysqli_num_rows($queryResult) == 1)  
        {
            echo ("<p>User is found, Successful login!</p>");   
            echo('<p><a href="memberadd.php">member add</a> </p>');
            echo('<p><a href="memberremove.php">List/Remove member</a> </p>');
            echo('<p><a href="logout.php">Log out</a> </p>');
            exit();

            $query2 = "SELECT member_name FROM team WHERE member_email = '$email' AND password= '$passw'";

            $queryResult2 = @mysqli_query($conn, $query2)
                        or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";


            $array = mysqli_fetch_row($queryResult2);       
            $_SESSION['membername'] = $array[0];
        }
        else
        {
            echo"<p>Email and password do not match</p>";
            echo'<p><a href="index.php">Home page</a> </p>';
        }
        }
        }


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/chtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="Web Programming :: Assignment 2" />
    <meta name="Keywords" content="Web, programming" />
    <title>Member Login</title>
</head>

<body>

<form id='login' action='login.php' method='POST'>
        <fieldset >
            <legend><h1>My Team System Log in Page</h1></legend>
            <?php $email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_SANITIZE_STRING) : ''; ?>
            <label for='email' >Email:</label>
                <input type='text' name='email' id='email' maxlength="50"  value="<?php echo $email; ?>" />
            </div>
                    <br />
            <div class="elements">
            <label for='password' >Password:</label>
                <input type='password' name='password' id='password' maxlength="50" />
            </div>
                    <br />
            <div class="submit">
                <input type='submit' name='login' value='Login' />
                <input type='reset' name='Submit' value='Clear' />
                    <br />
            <div class="elements">
            <a href="index.php">Home</a> 
        </fieldset>
</form>

</body>
</html>
4

5 回答 5

0

您将会话设置为,membername但您随后尝试调用name. 如中,您应该将显示用户名的位更正为$_SESSION['membername'].

于 2013-10-31T22:05:16.507 回答
0

我看到了 3 个错误 -
1. 你session_start()不在代码的顶部/开头。
2. 在设置会话值之前回显
3.exit();在回显之后和设置会话值之前使用。


此外,您对 sql 注入持开放态度,您应该散列您的密码。

于 2013-10-31T22:09:01.150 回答
0

好吧,我可以告诉您我所看到的:您将成员名称的会话设置为这样

$_SESSION['membername'] = $array[0];

但是在 memberadd.php 中,您可以像这样检索它:

echo "<p>Welcome back". "<br />".$_SESSION['name']."</p>";

因此,您应该更改为您将其设置为的相同名称:

echo "<p>Welcome back". "<br />".$_SESSION['membername']."</p>";
于 2013-10-31T22:14:45.937 回答
0

对不起,我在早期的文件上犯了一个错误,这是人们注册的注册文件,我在那里设置了会话名称 ['name'] 而不是 ['membername']。现在一切都好。

于 2013-10-31T22:26:28.050 回答
0

空白屏幕通常是解析错误...

echo "<p>Error with: ", $query, "</p>";

应该

echo "<p>Error with: ".$query."</p>"; 


echo "<td>",$row["member_name"],"</td>";

应该

echo "<td>".$row["member_name"]."</td>";
于 2013-10-31T22:05:53.757 回答