0

我还是 php 新手,正在努力学习。我有以下代码,变量 $username 和 password 没有被设置,我 99% 确信它们没有问题。

你能指导我做些什么来解决这个问题。每次我运行脚本时,我都会收到用户名和密码未设置消息(使用 if 语句设置)。

    <?php
        require 'connect.inc.php';

        if (isset($_POST['login_button'])&&($_POST['username'])&&($_POST['password'])){
                        $login_button = $_POST['login_button'];             
                        $username = $_POST['username'];
                        $password = $_POST['password'];

                            $password_hash = md5($password);

                                if(!empty($username)&&!empty($password)){
                                    $sql = "SELECT `id` FROM `golden_acres_username` WHERE `uname`='$username' AND `password`='$password_hash'";
                                        if($sql_run = mysql_query($sql)){
                                            $query_num_rows = mysql_num_rows($sql_run);
                                        }
                                            if($query_num_rows==0){
                                                echo mysql_result($sql_run);
                                            }
                                            else if($query_num_rows==1){
                                                echo 'ok';
                                            }
                                } else {
                                echo 'You must supply a username and a password.';
                                }
                            }

                     else {
                        echo $array;
                        echo 'Username and password are not set';
                    }
                    ?>
                        <form class="home_logon_area" action="" method="POST">
                        <table border="0">
                            <tr><td colspan="2">Username: </td></tr>
                            <tr><td colspan="2"><input type="text" class="text_field" name="username" size="30"/></td></tr>
                            <tr><td colspan="2">Password: </td></tr>
                            <tr><td colspan="2"><input type="password" class="text_field " type="password" name="password" size="30"/></td></tr>
                            <tr><td valign="top"><a class="home_content_link_form" href="no_password.html"> Forgor Password </a></td>
                                <td align="right" rowspan="2"><input type="submit" name="login_button" id="login_button" value="Login"/></td></tr>
                            <tr><td><a class="home_content_link_form" href="register.php"> Register </a></td></tr>
                        </table>
                        </form>
?>

提前致谢,

约瑟夫

4

1 回答 1

2

改变:

if (isset($_POST['login_button'])&&($_POST['username'])&&($_POST['password'])){

至:

if (isset($_POST['login_button']) && isset($_POST['username']) && isset($_POST['password'])){
于 2013-09-23T20:50:44.667 回答