-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAJAX_bestellung.php
112 lines (94 loc) · 3.91 KB
/
AJAX_bestellung.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
session_start();
require_once './Page.php';
class PageTemplate extends Page
{
// to do: declare reference variables for members
// representing substructures/blocks
/**
* Instantiates members (to be defined above).
* Calls the constructor of the parent i.e. page class.
* So the database connection is established.
*
* @return none
*/
protected function __construct()
{
parent::__construct();
// to do: instantiate members representing substructures/blocks
}
/**
* Cleans up what ever is needed.
* Calls the destructor of the parent i.e. page class.
* So the database connection is closed.
*
* @return none
*/
protected function __destruct()
{
parent::__destruct();
}
/**
* Fetch all data that is necessary for later output.
* Data is stored in an easily accessible way e.g. as associative array.
*
* @return none
*/
protected function getViewData()
{
}
protected function generateView()
{
$this->getViewData();
$this->processReceivedData();
}
protected function processReceivedData()
{
//parent::processReceivedData();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$bestellung = json_decode(file_get_contents("php://input"), true);
//header("Content-type: text/plain; charset=UTF-8");
// print_r($bestellung);
//$bestelltePizzen = $_POST['Bestellungen'];
// print_r($bestellung);
$Vorname = mysqli_real_escape_string($this->database, $bestellung['Vorname']);
$Nachname = mysqli_real_escape_string($this->database, $bestellung['Nachname']);
$Adresse = mysqli_real_escape_string($this->database, $bestellung['Adresse']);
$created_date = date("Y-m-d H:i:s");
echo $created_date;
$sql = "INSERT INTO `Bestellung` (`BestellungID`, `Adresse`, `Vorname`, `Nachname`, `Bestellzeitpunkt`) VALUES (NULL, '$Adresse', '$Vorname','$Nachname','$created_date');";
mysqli_query($this->database, $sql);
//print_r($bestellung);
for ($i = 0; $i < Count($bestellung['Pizzen']); $i++) {
$pizzaname = $bestellung['Pizzen'][$i]['name'];
echo ($pizzaname);
// $sql = "SELECT BestellungID FROM Bestellung WHERE Bestellzeitpunkt='$created_date' union SELECT PizzaNummer FROM Angebot WHERE PizzaName='$pizzaname';";
$sql = "SELECT b.BestellungID, a.PizzaNummer FROM Bestellung b, Angebot a WHERE b.Bestellzeitpunkt='$created_date' AND a.PizzaName='$pizzaname';";
$recordset = $this->database->query($sql);
$pizza = $recordset->fetch_all(MYSQLI_ASSOC);
print_r($pizza);
$fbestnummer = $pizza[0]['BestellungID'];
$fpizzanummer = $pizza[0]['PizzaNummer'];
$sqli = "INSERT INTO `BestelltePizza` (`PizzaID`, `fBestellungID`, `fPizzaNummer`, `Status`) VALUES (NULL, '$fbestnummer', '$fpizzanummer', 'Bestellung eingegangen');";
mysqli_query($this->database, $sqli);
}
$sql = "SELECT BestellungID FROM Bestellung WHERE BestellungID=(SELECT max(BestellungID) FROM Bestellung);";
$recordset = $this->database->query($sql);
$pizza23 = $recordset->fetch_all(MYSQLI_ASSOC);
$_SESSION['BestellungID'] = $pizza23[0]['BestellungID'];
echo ('Die Sessionvariable laute:' . $_SESSION['BestellungID']);
}
}
public static function main()
{
try {
$page = new PageTemplate();
//$page->processReceivedData();
$page->generateView();
} catch (Exception $e) {
header("Content-type: text/plain; charset=UTF-8");
echo $e->getMessage();
}
}
}
PageTemplate::main();