-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_signup.php
47 lines (38 loc) · 1.57 KB
/
process_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
<?php
include 'access.php';
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$newuname = $_POST['newuname'];
$newpsw = $_POST['newpsw'];
if (empty($name) || empty($surname) || empty($phone) || empty($newuname) || empty($newpsw)) {
header("Location: signup.php?error=emptyfields&name=".$name."&surname=".$surname."&phone=".$phone."&newuname=".$newuname);
exit();
} else {
// Insert user into the users table with plain text password
$sql = "INSERT INTO users (name, surname, phone, username, password) VALUES ('$name', '$surname', '$phone', '$newuname', '$newpsw')";
if (mysqli_query($con, $sql)) {
// Get the last inserted ID
$last_inserted_id = mysqli_insert_id($con);
// Insert corresponding record into the citizen table
$citsql = "INSERT INTO citizen (cit_id) VALUES ('$last_inserted_id')";
if (mysqli_query($con, $citsql)) {
// Set the user ID in the session
$_SESSION['user_id'] = $last_inserted_id;
$con->close();
header("Location: register_map.php");
exit();
} else {
echo "Error inserting into citizen table: " . mysqli_error($con);
}
} else {
echo "Error inserting into users table: " . mysqli_error($con);
}
}
} else {
header("Location: signup.php");
exit();
}
?>