3

I am trying to create a simple registration form. I have the following:

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);
    }
}

Here is the HTML form:

    <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>

Whenever I test it, I just get a blank page as a result. What did I do wrong? Also, (and where) do I display a confirmation message upon success or failure? Many thanks in advance!

Monica
  • 1,665
  • 2
  • 21
  • 33
  • There seems to be quite a lot of stuff going on for a simple register page. I would do something like create a function called (or something similar to) `register_me($un,$pw)` and pass in the values from `username` and `password`. Then inside the function, have the query to check to see if the user already exists; if not, insert into the table. If so, display an error and show the login or forgot password stuff. – dan Oct 04 '11 at 03:42

1 Answers1

4

Add method="post" to your form tag, also type="submit" to the register button.

Dan LaManna
  • 3,178
  • 4
  • 20
  • 31