-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.php
52 lines (42 loc) · 1.22 KB
/
logic.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
session_start();
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_REQUEST["name"];
$nachname = $_REQUEST["Nachname"];
$email = $_REQUEST["email"];
$password = $_REQUEST["Passwort"];
echo "$name";
echo "$nachname";
echo "$email";
echo "$password";
$salt="123124123124123";
$encrypted_pw = hash("sha256",$password.$salt);
$stmt = $conn->prepare('insert into user(Name,Nachname,email,password) values (?,?,?,?)');
$stmt->bind_param("ssss", $name, $nachname,$email,$encrypted_pw);
try {
$result = $stmt->execute();
if ($result) {
$_SESSION["successCreate"] = "Successfully created Account!";
header("Location: index.php");
exit;
}
} catch (mysqli_sql_exception $e) {
if ($e->getCode() === 1062) {
// Duplicate entry error
$_SESSION["errorCreate"] = "Email already exists!";
} else {
// Other SQL errors
$_SESSION["errorCreate"] = "Something went wrong for account creation!";
}
header("Location: index.php");
exit;
}