-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateNewUser.php
60 lines (38 loc) · 1.61 KB
/
createNewUser.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
session_start();
if (isset($_POST['username']) && isset($_POST['email']) && isset($_POST['password'])) {
require_once('db.class.php');
$username = $_POST['username'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$mysql = new db();
$connection = $mysql->Connect();
//Verify user exists
$sqlCommand = "SELECT * FROM users WHERE username = '$username' OR email = '$email'";
//Execute the command
$result = mysqli_query($connection, $sqlCommand);
if (!$result) {
echo 'There is an error in the database. Try again later.';
die();
} else {
$users = mysqli_fetch_array($result);
if (isset($users['userid'])) {
header('Location: signup.php?error=1');
die();
} else {
//Command
$sqlCommand = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$password')";
//Execute
if(mysqli_query($connection, $sqlCommand)) {
$_SESSION['userid'] = $connection->insert_id;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
header('Location: home.php');
} else {
echo 'There is an error trying to register you. Try again later.';
die();
}
}
}
}
?>