-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart-exec.php
79 lines (65 loc) · 2.72 KB
/
cart-exec.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
<?
/*****************************************************
Developer: macdonaldgeek
Email: [email protected]
Phone: +255-657-567401/+254-717-667201/+44-744-0579061
Twitter: @macdonaldgeek
COPYRIGHT ©2014 RESTAURANT SCRIPT. ALL RIGHTS RESERVED
******************************************************/
?>
<?php
//Start session
session_start();
//Include session details
require_once('auth.php');
//Include database connection details
require_once('connection/config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//checks if id is set in the url
if(isset($_GET['id'])){
//retrive the first quantity from the quantities table
$quantities=mysql_query("SELECT * FROM quantities")
or die("Something is wrong ... \n" . mysql_error());
$row=mysql_fetch_assoc($quantities);
$quantity_value = $row['quantity_value'];
//get id value
$food_id = $_GET['id'];
//retrive food_price from food_details based on $food_id
$result=mysql_query("SELECT * FROM food_details WHERE food_id='$food_id'") or die("A problem has occured ... \n" . "Our team is working on it at the moment ... \n" . "Please check back after few hours.");
$food_row=mysql_fetch_assoc($result);
$food_price=$food_row['food_price'];
//get member_id from session
$member_id = $_SESSION['SESS_MEMBER_ID'];
//define default values for quantity(got from $row), total($food_price*$quantity_value), and flag_0
$quantity_id = $row['quantity_id'];
$total = $food_price*$quantity_value;
$flag_0 = 0;
//Create INSERT query
$qry = "INSERT INTO cart_details(member_id, food_id, quantity_id, total, flag) VALUES('$member_id','$food_id','$quantity_id','$total','$flag_0')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: cart.php");
exit();
}else {
die("A problem has occured with the system " . mysql_error());
}
}
?>