Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP多步骤注册过程_Php_Html_Forms_Post_Mysqli - Fatal编程技术网

PHP多步骤注册过程

PHP多步骤注册过程,php,html,forms,post,mysqli,Php,Html,Forms,Post,Mysqli,我正在研究一个注册系统,该系统共包括3个步骤 步骤1-用户输入用户名,系统在数据库中搜索 用户名。如果找到用户名,它将检查帐户状态(即: 未创建密码,密码完整但未验证,未注册和 验证) 如果未找到用户,则将用户定向到步骤2 如果状态=未创建密码,则用户将被引导至步骤3 如果状态=完成但未验证/已注册并验证,则显示错误消息 步骤2-用户输入个人详细信息 该页面存储用户输入 步骤3-用户创建密码,系统连接到数据库并将用户信息插入用户表。成功的信息是 显示 通过在提交前一个表单时显示一个新表单,我已经

我正在研究一个注册系统,该系统共包括3个步骤

步骤1-用户输入用户名,系统在数据库中搜索 用户名。如果找到用户名,它将检查帐户状态(即: 未创建密码,密码完整但未验证,未注册和 验证)

如果未找到用户,则将用户定向到步骤2

如果状态=未创建密码,则用户将被引导至步骤3

如果状态=完成但未验证/已注册并验证,则显示错误消息

步骤2-用户输入个人详细信息

该页面存储用户输入

步骤3-用户创建密码,系统连接到数据库并将用户信息插入用户表。成功的信息是 显示

通过在提交前一个表单时显示一个新表单,我已经设法找出并完成了前两个步骤的编码

问题:然而,我刚刚意识到我无法从以前的表单中检索数据(即:在步骤3中,我无法从步骤1中检索用户名)。我尝试过使用“header('location:?user=$uname');”然而,这种方法不起作用,因为当我提交新表单时,URL被重置,并且我再次丢失了用户名。如何仅使用PHP创建适当的多步骤表单,如何存储输入值以便在最后一步使用它们。下面是我的代码:

<?php
include 'includes/session_info.php';
if(isset($_SESSION['user_id'])){
    header('Location: index.php');
}
$errors = array();
if(empty($_POST['user_info']) === false){
    require ('core/dbcon.php');
    $usr_email = mysqli_real_escape_string($con, $_POST['email']);
    $usr_joined = mysqli_real_escape_string($con, $_POST['joined']);
    $usr_recruited = mysqli_real_escape_string($con, $_POST['recruited']);
    if($usr_email){
        //direct user to password form
    }else{
        $errors[] = 'Please complete all fields marked with a Red Asterisk.';
    }
    $form2 = $usr_email.'<br>'.$usr_joined.'<br>'.$usr_recruited;
}
if(empty($_POST['username_chck']) === false){
    require ('core/dbcon.php');
    $username = mysqli_real_escape_string($con, $_POST['uname']);
    $rpt_uname = mysqli_real_escape_string($con, $_POST['r_uname']);
    if($username && $rpt_uname){
        if($username == $rpt_uname){
            $query = mysqli_query($con, "SELECT status FROM users WHERE username = '$username'") or die(mysqli_error($con));
            // Display registration form if Username is not found.
            if(mysqli_num_rows($query) == 0){
                $form1;
            }
            // Actions performed If username entered already exists in the database.
            elseif(mysqli_num_rows($query) == 1){
                $status = mysqli_fetch_assoc($query);
                if($status['status'] == 0){
                    $errors[] = '<b>'.$username.'</b> is already registered and awaiting to be verified by our admins. Feel free to contact an Admin via the website or in-game to get verified.';
                }elseif($status['status'] == 1){
                    //header("Location:?create_pwd&user=$username");
                }elseif($status['status'] > 1){
                    $errors[] = '<b>'.$username.'</b> is already registered and verified by our Admins. Please log in to access you account.
                    If you have forgotten your password you can rest your password <a class="navbar-link error_link" id="intext-link" href="login.php?fp"><b>here</b></a>.';
                }
            }elseif(mysqli_num_rows($query) > 1){
                $errors[] = 'An error has occurred. Looks like a there is more than one member with that username. Please contact the Administrator for assistance.';
            }
        }else{
            $errors[] = 'Please ensure that the username entered in both fields match.';

        }
    }else{
        $errors[] = 'Please complete all required fields.';
    }
}



如上所述,将每个步骤的POST数据存储在会话变量中

// Step 1 submit
$_SESSION['steps'][1] = $_POST;

// Step 2 submit
$_SESSION['steps'][2] = $_POST;

// Step 3 submit
$_SESSION['steps'][3] = $_POST;
然后,您可以在会话中使用类似currentStep的内容来确定它们最后的位置

$currentStep = $_POST['step'];

并与您需要的可用数据进行比较,或者直接从数组中使用。

我选择使用“隐藏变量”方法,将上一个表单中的值存储在当前表单的隐藏输入中。从而使我能够将值传递到下一个表单。一种雪球效应,如果你愿意的话。以下是一个例子:

表格1


将每个表单中需要使用的内容放入
$\u会话中(和/或使用隐藏输入),我试过了。除了现有的登录会话之外,我还创建了一个新的“注册会话”。我存储了这些值,并为它们指定了唯一的名称。然而,它似乎干扰了我的登录会话(即:如果我登录并注销,我的会话将不会存储第二个表单中的值。我可能会使用隐藏值。只是想知道是否有更好的方法。将第二个步骤中的所有详细信息存储为json格式,并按照上述注释中的建议将其存储在会话中。您的会话替代方案看起来很有希望。如果我需要,我可能会尝试这样做。)用我的方法解决任何问题。
$currentStep = $_POST['step'];
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="form-group">
    <label for="Email">Email: </label>
    <input type="email" name="email" class="form-control" id="Email" required <?php if (isset($_POST['email'])=== true){echo 'value="', strip_tags($_POST['email']),'"';}?>>
</div>
<input type="hidden" name="username" <?php if (isset($_POST['username'])=== true){echo 'value="', strip_tags($_POST['username']),'"';}else{echo "value=\"$username\"";}?>>
<input type="submit" name="user_info" class="btn btn-default" value ="Next">
if(empty($_POST['form1'])=== false){
       $username = mysqli_real_escape_string($con, $_POST['username']);
       // display form 2
}elseif(empty($_POST['form2'])=== false){
       //display form 3
}