forked from dbosman/BitcoinFaucet-Simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
41 lines (36 loc) · 1.2 KB
/
register.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$conn = mysqli_connect("localhost", "dbuser", "dbpassword", "dbname");
if (mysqli_connect_errno()){
echo "Connection to DB failed" . mysqli_connect_error();
}
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['pw'];
$username = mysqli_real_escape_string($conn, $username);
$password = mysqli_real_escape_string($conn, $password);
$enc_pass = md5($password);
//check for duplicate usernames
$dupName = mysqli_query($conn, "SELECT * FROM users WHERE user = '$username'");
$rowName = mysqli_num_rows($dupName);
if ($rowName != 0) {
$message = "Username is already in use, pick another";
} else {
mysqli_query($conn, "INSERT INTO users (user, pw) VALUES ('$username', '$enc_pass')");
$message = "Account Successfully Created";
mysqli_close($conn);
}
}
?>
<html>
<body>
<h1>Register for Free Bitcoins!</h1>
<br>
<form name="register" method="post" action="register.php">
Username: <input type="text" name="username" maxlength="15" /><br>
Password: <input type="password" name="pw" /><br>
<input type="submit" name="submit" value="Register" />
</form>
<?php echo $message; ?><br>
<a href="login.php">Already Registered? Login Here </a>
</body>
</html>