0

我正在尝试创建一个真正的“简单登录注册”页面。

我有一个 wordpress 页面模板,当有人去 ie /signup 时,他们会收到一个要求他们提供密码的输入,如果这个密码正确,输入将更改为我创建的表单,他们可以填写然后发送。

表格已经到位并且效果很好。它看起来像这样:

<?php
if(isset($_POST['submit'])) {

// Required field names
$required = array('fullname','email','country','age','gender','os','cpu','ram','gfx','hdd','speed');

// Loop over field names, make sure each one exists and is not empty
$error = false;
    foreach($required as $field) {
        if (empty($_POST[$field])) {
            $error = true;
        }
    }
    if ($error) {
        echo '<label class="error">There was an error with your application. <br />Please make sure you have filled in everything marked with an asterisk.</label>';
    } else {
        $username="user";
        $password="root";
        $database="database";
        $host="localhost";

        $link = mysqli_connect($host, $username, $password);
        mysqli_select_db($link, $database) or die("Unable to select database");

        $fullname = mysqli_real_escape_string($link, $_POST['fullname']);
        $email = mysqli_real_escape_string($link, $_POST['email']);
        $country = mysqli_real_escape_string($link, $_POST['country']);
        $age = mysqli_real_escape_string($link, $_POST['age']);
        $gender = mysqli_real_escape_string($link, $_POST['gender']);
        $beta = mysqli_real_escape_string($link, $_POST['beta']);
        $press = mysqli_real_escape_string($link, $_POST['press']);
        $os = mysqli_real_escape_string($link, $_POST['os']);
        $cpu = mysqli_real_escape_string($link, $_POST['cpu']);
        $ram = mysqli_real_escape_string($link, $_POST['ram']);
        $gfx = mysqli_real_escape_string($link, $_POST['gfx']);
        $hdd = mysqli_real_escape_string($link, $_POST['hdd']);
        $speed = mysqli_real_escape_string($link, $_POST['speed']);

        $query = "SELECT * FROM enroll WHERE email='$email'";
        $result = mysqli_query($link, $query) or die(mysqli_error($link));

        if (mysqli_num_rows($result) ) {
            print '<label class="error">That Email address is already registered acording to our records</label>';
        }
        else {
            $query = "INSERT INTO enroll_beta VALUES ('','$fullname','$email','$country','$age','$gender','$beta','$press','$os','$cpu','$ram','$gfx','$hdd','$speed')";
            $result = mysqli_query($link, $query) or die(mysqli_error($link));

                print '<label class="success">Thank you for your participation, we will be in touch</label>';
        }
    }   
}

表格如下所示:

<form class="betaform" method="post" action="<?php echo esc_attr($_SERVER['REQUEST_URI']); ?>">

所以我现在想做的是将整个事情包装在一个简单的密码保护脚本中,该脚本基本上只是检查我的数据库中名为“密码”的另一个表,如果密码存在于数据库中,它将与表单一起“回显”上面的代码。

我已经尝试过使用我在这里找到的会话脚本:密码保护页面?(具有数据库访问权限)

看起来不错,但我不认为 session 对我有用,因为我想把所有这些都放在一个没有连接的页面上。

有什么想法或想法吗?我迷路了,我一直在像疯子一样寻找。

提前致谢!

4

0 回答 0