-1

我在这里有“检查”,如果发生了什么事,它会echo是一个短语The username you supplied is already in use或其他什么。但是,当它确实显示它时,它只会在带有该文本的空白页面上显示它。这里有什么问题?

PHP

<?php
    include('./dbconnect/global.php');

    if ($_POST['register']) {
        $username = mysql_real_escape_string(strip_tags($_POST['username']));
        $password = mysql_real_escape_string(strip_tags($_POST['password']));
        $email = mysql_real_escape_string(strip_tags($_POST['email']));

        if (!$username||!$password||!$email)
            echo "PLease Fill in The Required Fields";
        else {
            //check if username is taken
            $check = mysql_query("SELECT * FROM users WHERE username='$username'");
            if (mysql_num_rows($check) >= 1)
                echo "The Username you Supplied Is Already in Use! <a href='./register'>Back</a>";
            $check2 = mysql_query("SELECT * FROM users WHERE email='$email'");
            if (mysql_num_rows($check) >= 1)
                echo "The Email you Supplied Is Already in Use! <a href='./register'>Back</a>";
            else {
                $password2 = md5($password);
                $register = mysql_query("value and stuff)") or die(mysql_error());
                echo "Thanks for registering, $username! <a href='./index'>Home</a>";
            }
        }
    }

    else {
?>

HTML

<html>

<head>

    <title>CoreCrafters</title>
    <link rel="stylesheet" type="text/css" href="./css/main.css">

</head>

<body>

    <?php include('./include/nbar.php') ?>

    <div id="main">

        <div id="register">
            <div id="wrapper">
                <form action="register" method="POST">
                    Username
                    <br />
                    <input type="username" name="username">
                    <br />
                    Password
                    <br />
                    <input type="password" name="password">
                    <br />
                    Email
                    <br />
                    <input type="email" name="email">
                    <br /><br />
                    <input type="submit" name="register" value="Register">
                </form>
            </div>
        </div>

    </div>

    <?php include('./include/footer.php') ?>

</body>

</html>

结束 PHP(最后来自 ELSE)

<?php
    }
?>

CSS

body {
    margin: 0;
    padding: 0;
    background-color: #EEE;
}

#headerbar {
    width: 100%;
    background-color: #000;
}

a {
    color: #069;
    font-weight: bold;
    text-decoration: none;
    transition: all 0.2s linear;
    -o-transition: all 0.2s linear;
    -ms-transition: all 0.2s linear;
    -moz-transition: all 0.2s linear;
    -webkit-transition: all 0.2s linear;
}

a:hover { 
    color: #c00;
}

#nav {
    padding: 0;
    width: 100%;
    float: left;
    list-style: none;
    margin: 0 0 3em 0;
    background-color: #f2f2f2;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc; 
}

#nav li {
    float: left;
}

#nav li a {
    color: #069;
    display: block;
    font-weight: bold;
    padding: 8px 15px;
    text-decoration: none;
    transition: all 0.2s linear;
    border-right: 1px solid #ccc;
    -o-transition: all 0.2s linear;
    -ms-transition: all 0.2s linear;
    -moz-transition: all 0.2s linear;
    -webkit-transition: all 0.2s linear;
}

#nav li a:hover {
    color: #c00;
    background-color: #fff;
}

#footer {
    width: 94%;
    padding: 10px;
    margin-top: 10px;
    margin-left: auto;
    padding-left: 0px;
    text-align: center;
    margin-right: auto;
    padding-right: 0px;
    border: 1px solid #DDD;
    background-color: #FFF;
}

#main {
    width: 94%;
    margin-top: 50px;
    min-height: 500px;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid #DDD;
    background-color: #FFF;
}

#register {
    width: 15%;
    margin-top: 20px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: #CCC;
    border: 1px solid #AAA;
}

#logbar {
    width: 150px;
    float: right;
    min-height: 36px;
    padding-left: 5px;
    padding-right: 50px;
    background-color: #DDD;
}

根据要求,我将大部分页面发布到这里。

4

2 回答 2

1

您的网页除了回显之外没有其他内容,因此它在空白页面上回显它,因为您告诉它这样做。

  • 更新:代码

    <!DOCTYPE html>
    <html class="no-js">
    <head>
        <meta charset="utf-8"> <!-- UXSS UTF-7 (IE6) prevention -->
        <title>CoreCrafters</title>
        <link rel="stylesheet" type="text/css" href="./css/main.css">
    </head>
    <body>
    <?php @include('./include/nbar.php'); ?>
    <div id="main">
        <div id="register">
            <div id="wrapper">
                <form method="POST">
                    Username<br /><input type="username" name="username"><br />
                    Password<br /><input type="password" name="password"><br />
                    Email<br /><input type="email" name="email"><br /><br />
                    <input type="submit" name="register" value="Register">
                </form>
            </div>
    <?php
    @include('./dbconnect/global.php');
    
    if (isset($_POST['register'])) {
        if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email'])) {
            die('Please fill out the required fields.');
        } else {
            $query = mysql_query("SELECT * FROM users WHERE username = '" . mysql_real_escape_string($_POST['username']) . "'");
            if (mysql_num_rows($query)) { die('The username you provided is already in use!'); }
    
            $query = mysql_query("SELECT * FROM users WHERE email = '" . mysql_real_escape_string($_POST['email']) . "'");
            if (mysql_num_rows($query)) { die('The email you provided is already in use!'); }
    
            /** Insert values **/
    
            echo 'Thanks for registering, ' . htmlentities($_POST['username'], ENT_QUOTES) . '!'; /** Normal XSS prevention **/
       }
    }
    ?>
        </div>
    </div>
    <?php @include('./include/footer.php'); ?>
    </body>
    </html>
    
于 2012-10-21T00:35:00.407 回答
0

我相信您的include语句(在 HTML 块内)缺少分号。如:

<?php include('./include/footer.php'); ?>

如果这不能解决它,你应该检查你的错误日志。当 PHP 解析器无法解析您的代码时,您通常会得到一个完全空白的页面。

于 2012-10-21T02:12:59.483 回答