· 9 years ago · May 04, 2017, 07:34 AM
1<?php
2//Add SQL paths
3require "../admin/paths.php";
4// Connects to your Database
5mysql_connect("$SQLHOST", "$SQLUSER", "$SQLPASS") or die(mysql_error());
6mysql_select_db("$SQLDB") or die(mysql_error());
7//Create DB table 'users' + fields ID, user and pass
8CREATE TABLE users (ID MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(60), password VARCHAR(60))
9
10//This code runs if the form has been submitted
11if (isset($_POST['submit'])) {
12
13//This makes sure they did not leave any fields blank
14if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
15die('You did not complete all of the required fields');
16}
17
18// checks if the username is in use
19if (!get_magic_quotes_gpc()) {
20$_POST['username'] = addslashes($_POST['username']);
21}
22$usercheck = $_POST['username'];
23$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
24or die(mysql_error());
25$check2 = mysql_num_rows($check);
26
27//if the name exists it gives an error
28if ($check2 != 0) {
29die('Sorry, the username '.$_POST['username'].' is already in use.');
30}
31
32// this makes sure both passwords entered match
33if ($_POST['pass'] != $_POST['pass2']) {
34die('Your passwords did not match. ');
35}
36
37// here we encrypt the password and add slashes if needed
38$_POST['pass'] = md5($_POST['pass']);
39if (!get_magic_quotes_gpc()) {
40$_POST['pass'] = addslashes($_POST['pass']);
41$_POST['username'] = addslashes($_POST['username']);
42}
43
44// now we insert it into the database
45$insert = "INSERT INTO users (username, password)
46VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
47$add_member = mysql_query($insert);
48?>
49
50
51<h1>Registered</h1>
52<p>Thank you, you have registered - you may now login</a>.</p>
53
54<?php
55}
56else
57{
58?>
59
60
61<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
62<table border="0">
63<tr><td>Username:</td><td>
64<input type="text" name="username" maxlength="60">
65</td></tr>
66<tr><td>Password:</td><td>
67<input type="password" name="pass" maxlength="10">
68</td></tr>
69<tr><td>Confirm Password:</td><td>
70<input type="password" name="pass2" maxlength="10">
71</td></tr>
72<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
73</form>
74
75<?php
76}
77?>