检查数据库中的用户名和确认代码并重定向到创建密码页面

时间:2017-04-17 23:46:47

标签: php html sql

我正在尝试使用系统查找用户名和确认码,然后重定向并让该用户(如果确认码匹配)为其帐户创建密码(不确定如何做到这一点)。

我在几年前使用php修改了一下,但事情发生了变化,我正在为它提供裸骨设置页面。我需要一些大时间的帮助,因为我似乎无法找到任何接近我想要的东西。注册系统在游戏中,所以它允许你点击一个框,它会在游戏中向你发送一个确认码,这意味着你已经注册,只需要制作一个PW。

所以

  1. 首页检查用户名和确认码(确保确认码正确)
  2. 第二页允许用户为其帐户创建密码并将其插入到帐户中。
  3. 第3页显示帐户已设置,并具有登录的基本链接。
  4. 这是下面的基本代码:(总是返回0的计数无法通过它)

        <?php
    include( "config.php" );
    session_start();
    if( $_SERVER["REQUEST_METHOD"] == "POST" )
    {
        // username and password sent from form
        $myusername = mysqli_real_escape_string( $db,$_POST['username'] );
        $myconfrimcode = mysqli_real_escape_string( $db,$_POST['confirmcode'] );
        $sql = "SELECT * FROM accounts WHERE username = '$myusername' and confirmcode = '$myconfirmcode'";
        $result = mysqli_query( $db,$sql );
        $row = mysqli_fetch_array( $result );
        $active = $row['active'];
        $count = mysqli_num_rows( $result );
        // If result matched $myusername and $myconfirmcode, table row must be 1 row
        if( $count == 1 )
        {
            session_register( "myusername" );
            $_SESSION['real_user'] = $myusername;
            redirect( "create.php" );
            exit();
        }
        else
        {
            $error = "ERROR: Your User Name or Confirm Code is invalid<br>POST USER: ".$_POST['username']."<br>POST Confirm Code: ".$_POST['confirmcode']."<br>myusername: ".$myusername."<br>myconfirmcode: ".$myconfirmcode."<br> Result Count: ".$count;
        }
    }
    ?>
    
    <html>
    <head>
    <title>Account Setup Portal</title>
    
    <style type = "text/css">
                  body
    {
    font-family:Arial, Helvetica, sans-serif;
        font-size:14px;
    }
    label
    {
    font-weight:
        bold;
        width:100px;
        font-size:14px;
    }
    .box
    {
    border:
    #666666 solid 1px;
    }
    .middleDiv
    {
    position :
        absolute;
        width    : 300px;
        height   : 500px;
        left     : 50%;
        top      : 50%;
    margin-left :
        -150px; /* half of the width  */
    margin-top  :
        -250px; /* half of the height */
    }
    </style>
    
    </head>
    
    <body class="middleDiv" bgcolor = "#000000">
    
    <div align = "center">
    <div style = "width:300px; border: solid 1px #0000A0;" align = "center">
    <div style = "background-color:#0000A0; color:#FDD017; padding:3px;"><b>Account Setup Portal</b></div>
    
    <div style = "color:#FDD017; margin:30px">
    
    <form action = "" method = "post">
    <label>User Name  :</label><input style = "background-color:#6D6968;" type = "text" name = "username" class = "box"/><br/><br/>
    <label>Password   :</label><input style = "background-color:#6D6968;" type = "text" name = "confirmcode" class = "box"/><br/><br/>
    <input type = "submit" value = " Engage! "/><br />
    </form>
    
    <div style = "font-size:13px; font-weight: 600; color:#cc0000; margin-top:10px"><?php echo $error;?></div>
    
    </div>
    
    </div>
    
    </div>
    
    </body>
    </html>
    

    我已经多次尝试过这个工作,我没有在PW创建页面上烦恼,因为我无法让这个页面正常工作。任何建议或帮助都会很棒,我会在这里与所有优秀人士联系,希望大家能帮助我解决这个系统的问题!

    (修复是为了纠正错误拼写的单词,并删除重定向链接,这也是我需要它的功能!)

1 个答案:

答案 0 :(得分:1)

您在定义时错误拼写了$ myconfirmcode。

 $myconfrimcode = mysqli_real_escape_string( $db,$_POST['confirmcode'] );
 $sql = "SELECT * FROM accounts WHERE username = '$myusername' and confirmcode = '$myconfirmcode'";