Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('functions.php');
- dbConnect('localhost', 'root', '', 'website');
- session_start();
- if(isset($_POST['submit'])){
- if(isset($_POST['username'], $_POST['password'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- $errors = array();
- if(empty($username)) {
- $errors[] = "Please enter a username.";
- }
- if(empty($password)) {
- $errors[] = "Please enter a password.";
- }
- if(strlen($username) <= 3) {
- $errors[] = "Please make sure your username is 4 or more characters long.";
- }
- if(strlen($password) <= 4) {
- $errors[] = "Please make sure your password is 5 or more characters long.";
- }
- if(count($errors)) {
- echo "The following errors occured:";
- foreach($errors AS $error) {
- echo $error."<br/>";
- }
- }else {
- $sql = "SELECT `username` FROM `users` WHERE `username` = '$username'";
- $res = mysql_query($sql);
- $count = mysql_fetch_row($res);
- if($count < 0) {
- //Insert the user into the db as the given username is available.
- $insertMember = "INSERT INTO `users` (username, password) VALUES ({$username}, {$password})";
- $addMember = mysql_query($sql) or die(mysql_error());
- header("Refrehs: 5;url=login.php");
- echo "You have successfully registered, redirecting you to the login page.";
- } else {
- echo "Sorry but the given username is not available.";
- }
- }
- }
- }
- ?>
- <html>
- <head>
- <title> Register </title>
- </head>
- <body>
- <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
- <p> Username: <input type="username" name="username" /> </p>
- <p> Password: <input type="password" name="password" /> </p>
- <input type="submit" name="submit" value="Register" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement