-
Notifications
You must be signed in to change notification settings - Fork 1
/
signup.php
56 lines (44 loc) · 1.48 KB
/
signup.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
<?php
include 'header.php';
$name = $_POST['nickname'];
$email = $_POST['email'];
$password = $_POST['password'];
$nameFieldLength = strlen($name);
$passwordLength = strlen($password);
$nameRegEx = '/^[a-zA-Z0-9.üäöß._-]*$/';
$emailRegEx = '/^[a-zA-Z0-9.ü._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
//check RegEx rules
if(!preg_match($nameRegEx, $name) || !preg_match($emailRegEx, $email) || $nameFieldLength < 3 || $passwordLength < 3)
header("Location: settingsSignup.php?regisError=wrongValues");
else
{
//check if username or email already exists
$sql = "SELECT COUNT(*)
FROM fhs_members
WHERE nme LIKE ? || email LIKE ?";
$stmt = $connect -> prepare($sql);
$stmt -> bind_param('ss', $name, $email);
$stmt -> execute();
$stmt -> bind_result($locatedUsers);
$stmt -> fetch();
$stmt -> close();
if($locatedUsers > 0)
header("Location: settingsSignup.php?regisError=alreadyInUse");
else
{
$initialBasket = "Deine persönlicher Einkaufsliste";
$initialProduct = "";
$productsArray = array();
$productString = serialize($productsArray);
$stmt2 = $connect->stmt_init();
$stmt2 -> prepare("INSERT INTO fhs_members (nme, email, pw) VALUES (?,?,?)");
$stmt2 -> bind_param('sss', $name, $email, $password);
$stmt2 -> execute();
$stmt2 -> prepare("INSERT INTO fhs_baskets (usernme, nme, product) VALUES (?,?,?)");
$stmt2 -> bind_param('sss', $name, $initialBasket, $productString);
$stmt2 -> execute();
$stmt2 -> close();
header("Location: index.php");
}
}
?>