-
Notifications
You must be signed in to change notification settings - Fork 0
/
save-user-datae.php
74 lines (72 loc) · 3.3 KB
/
save-user-datae.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
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
session_start();
if (!isset($_SESSION['ticket'])) {
header('Location: buy-ticket.php');
exit();
}
if (!isset($_POST['name']) && !isset($_POST['last-name']) && !isset($_POST['email']) && !isset($_POST['adress']) && !isset($_POST['postal-code']) && !isset($_POST['city']) && !isset($_POST['tel']) && !isset($_POST['regulamin'])) {
header('Location: your-data.php');
exit();
} else {
require_once './db_config.php';
if (isset($_SESSION['logged']) && $_SESSION['logged'] == true) {
$sql = "SELECT idKlienta FROM klienci WHERE `login` = ?";
$stmt = mysqli_prepare($mysql, $sql);
$stmt->bind_param('s', $_SESSION['user']);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) {
$client = mysqli_fetch_assoc($result)['idKlienta'];
}
} else {
$mail = $_POST['email'];
$sql = "SELECT idKlienta FROM klienci WHERE mail = ?";
$stmt = mysqli_prepare($mysql, $sql);
$stmt->bind_param('s', $mail);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) {
$client = mysqli_fetch_assoc($result)['idKlienta'];
} else {
$name = $_POST['name'];
$lastName = $_POST['last-name'];
$adress = $_POST['adress'];
$postalCode = $_POST['postal-code'];
$city = $_POST['city'];
$tel = $_POST['tel'];
$sql = "INSERT INTO `klienci`(`imie`, `nazwisko`, `mail`, `adres`, `kod_pocztowy`, `miejscowosc`, `nr_telefonu`) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($mysql, $sql);
$stmt->bind_param('sssssss', $name, $lastName, $mail, $adress, $postalCode, $city, $tel);
$stmt->execute();
$result = $stmt->get_result();
$sql = "SELECT idKlienta FROM klienci WHERE mail = ?";
$stmt = mysqli_prepare($mysqli, $sql);
$stmt->bind_param('s', $mail);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) {
$client = mysqli_fetch_assoc($result)['idKlienta'];
}
}
}
if ($client != '') {
$places = $_SESSION['places'];
foreach ($places as $place) {
$row = substr($place, 0, strpos($place, '-'));
$m = substr($place, strpos($place, '-')+1);
$sql = "INSERT INTO `rezerwacje`(`Klienci_idKlienta`, `Seanse_idSeansu`, `Bilety_idBiletu`, `miejsce`, `rzad`) VALUES (?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($mysql, $sql);
$stmt->bind_param('iiiii', $client, $_SESSION['seans'], $_SESSION['ticket'], $m, $row);
$stmt->execute();
$result = $stmt->get_result();
}
}
if ($result !== '') {
if (!isset($_SESSION['logged']) || $_SESSION['logged'] !== true) {
$_SESSION['mail'] = $mail;
}
$_SESSION['succes'] = true;
header('Location: confirmation.php');
}
}
?>