-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.php
90 lines (82 loc) · 2.47 KB
/
order.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cake_factory";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
echo"
<script type=\"text/javascript\">
if ( window.confirm('Oops, Connection failed. Just click OK to redirect to homepage.') ) {
window.location.href='http://localhost/CakeFactory/';
}
</script>
";
//die("Connection failed: " . mysqli_connect_error());
}
$cost = $_POST["cost"];
switch ($cost) {
case 300 :
$type = 'Cake 1';
break;
case 400 :
$type = 'Cake 2';
break;
case 500 :
$type = 'Cake 3';
break;
case 600 :
$type = 'Cake 4';
break;
case 700 :
$type = 'Cake 5';
break;
default:
echo"
<script type=\"text/javascript\">
if ( window.confirm('Oops, Something went wrong. Just click OK to redirect to homepage.') ) {
window.location.href='http://localhost/CakeFactory/';
}
</script>
";
break;
}
$weight = $_POST["weight"];
$total = $_POST["total"];
$sql = "INSERT INTO order_details (Type, Weight, Amount) VALUES ('".$type."', ".$weight.", ".$total.")";
$to = '[email protected]';
$subject = 'Order from Cake Factory';
$headers = "From: [email protected]\r\n";
$message = "Congrats!\r\nOrder details:-\r\nType: ".$type."\r\nWeight: ".$weight."\r\nTotal: ".$total."\r\nThank You.";
if (mysqli_query($conn, $sql)) {
if (mail($to, $subject, $message, $headers)) {
echo"
<script type=\"text/javascript\">
if ( window.confirm('Congrats, Order has been placed. Just click OK to redirect to homepage.') ) {
window.location.href='http://localhost/CakeFactory/';
}
</script>
";
// header('Location: http://localhost/CakeFactory');
// exit;
} else {
echo"
<script type=\"text/javascript\">
if ( window.confirm('Oops, Mail could not be send. Just click OK to redirect to homepage.') ) {
window.location.href='http://localhost/CakeFactory/';
}
</script>
";
}
} else {
echo"
<script type=\"text/javascript\">
if ( window.confirm('Oops, Order could not placed. Just click OK to redirect to homepage.') ) {
window.location.href='http://localhost/CakeFactory/';
}
</script>
";
//echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>