-
Notifications
You must be signed in to change notification settings - Fork 0
/
register-engine.php
61 lines (44 loc) · 2.3 KB
/
register-engine.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
61
<?php
$mysqli= new mysqli('magic.philosophy.ubc.ca', 'root', 'PhiloMagic2015!', 'whately');
// check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if((!empty($_POST['name'])) and (!empty($_POST['e-mail'])) and (!empty($_POST['user-name2'])) and (!empty($_POST['password2'])))
{
$name = $_POST['name'];
$email = $_POST['e-mail'];
$username = $_POST['user-name2'];
$password = $_POST['password2'];
}
$name = mb_convert_encoding ( $name, "UTF-8",mb_detect_encoding($name));
$email = mb_convert_encoding ( $email, "UTF-8",mb_detect_encoding($email));
$username = mb_convert_encoding ( $username, "UTF-8",mb_detect_encoding($username));
$password = mb_convert_encoding ( $password, "UTF-8",mb_detect_encoding($password));
$stmt1 = $mysqli -> prepare("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
$stmt1 -> execute();
//Check if the email or the username already exists.
$stmt = $mysqli -> prepare("SELECT `name` FROM `users` WHERE (`e-mail` = ?) OR (`username` = ?)");
$stmt -> bind_param('ss', $email, $username);
$stmt -> execute();
$stmt->bind_result($nameRe);
/* fetch value */
$stmt->fetch();
if((empty($nameRe))){
$stmt = $mysqli -> prepare("INSERT INTO `users`( `name`, `e-mail`, `username`, `password`) VALUES (?, ?, ?, ?)");
$stmt -> bind_param('ssss', $name, $email, $username, $password);
$stmt -> execute();
$stmt->close();
$registerMessage = 1;
$registerMessageCookie = 'register-Message-cookie';
setcookie($registerMessageCookie, $registerMessage, time() + 10, '/');
echo "<script>window.location.href='http://magic.philosophy.ubc.ca/argumentMapping/graph.php';</script>";
$mysqli->close();
} else {
$registerMessage = 0;
$registerMessageCookie = 'register-Message-cookie';
setcookie($registerMessageCookie, $registerMessage, time() + 10, '/');
echo "<script>window.location.href='http://magic.philosophy.ubc.ca/argumentMapping/graph.php';</script>";
}
?>