php - 为了使此注册表单发挥作用,我缺少什么?

标签 php mysql forms user-registration

我正在尝试创建一个简单的注册表单。我有以下内容:

include('User.datatype.php');

class NewUser {

    function inquireSubmit() {
        if(isset($_POST['register'])) {
            $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
            $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
            }
        else {
            exit;
            }
    }

    function registerUser() {
        if ($username = '' or $password = '') {
            $msg = 'Please enter the required information.';
            header('Location: index.php?error=$msg');
            }

        else {
            $user = new User;
            $user->username = $username;
            $user->password = $password;
            $user->profile = $profile;
            }
    }
}

class UserManager {
    public function storeData() {
        $database = mysql_connect("localhost", "root", "");
        mysql_select_db("test") or die(mysql_error());

        $username_e = mysql_real_escape_string($NewUser->username);
        $password_e = mysql_real_escape_string($NewUser->password);

        $query = "INSERT INTO users (username, password) VALUES ($username_e, $password_e)";
        mysql_query($query);
    }
}

这是 HTML 表单:

    <form id="register" action="register.php">
            <table cellpadding="2" cellspacing="2" border="0">
                <tr valign="top">
                    <td>
                        Username: <input name="username" type="text" id="username" />
                    </td>
                </tr>
                <tr valign="top">
                    <td>
                        Password: <input name="password" type="password" id="password" />
                    </td>
                    <td>
                        <button id="register">Register</button>
                    </td>
                </tr>
            </table>
    </form>

每当我测试它时,结果都是空白页。我做错了什么?另外,(以及在哪里)我在成功或失败时显示确认消息?非常感谢!

最佳答案

将 method="post"添加到您的表单标记,同时在注册按钮中键入“submit”。

关于php - 为了使此注册表单发挥作用,我缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7642574/

相关文章:

php - 数据库 phpmyadmin 上的图像路径不起作用

html - 无法使用百分比宽度对齐表单元素的右边缘

forms - 使用下拉列表更改表单内容

php - 通过比较 2 个数组,输入 <select> 在 PHP 中选择无法正常工作

phpunit 检查测试类上是否调用了方法

php - ActiveRecord 批量插入 (yii2)

php - 在执行员工搜索之前我收到以下错误

php - SQL 将 "-large"附加到列名称为 "clean_name"的每隔一行

MySQL:排除子查询中收集的同一个表中的项目

forms - CakePHP 3 - patchEntities() 的表单数据格式