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
| <?php
function insert_order($order_details)
{
global $HTTP_SESSION_VARS;
extract($order_details);
if(!$ship_name&&!$ship_address&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country)
{
$ship_name = $name;
$ship_address = $address;
$ship_city = $city;
$ship_state = $state;
$ship_zip = $zip;
$ship_country = $country;
}
$conn = db_connect();
$query = "select customerid from customers where
name = '$name' and address = '$address'
and city = '$city' and state = '$state'
and zip = '$zip' and country = '$country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
{
$customer_id = mysql_result($result, 0, 'customerid');
}
else
{
$query = "insert into customers values
('', '$name','$address','$city','$state','$zip','$country')";
$result = mysql_query($query);
if (!$result)
return false;
}
$query = "select customerid from customers where
name = '$name' and address = '$address'
and city = '$city' and state = '$state'
and zip = '$zip' and country = '$country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$customerid = mysql_result($result, 0, 'customerid');
else
return false;
$date = date('Y-m-d');
$query = "insert into orders values
('', $customerid, ".$HTTP_SESSION_VARS['total_price'].", '$date', 'PARTIAL', '$ship_name',
'$ship_address','$ship_city','$ship_state','$ship_zip',
'$ship_country')";
$result = mysql_query($query);
if (!$result)
return false;
$query = "select orderid from orders where
customerid = $customerid and
amount > ".$HTTP_SESSION_VARS['total_price']."-.001 and
amount < ".$HTTP_SESSION_VARS['total_price']."+.001 and
date = '$date' and
order_status = 'PARTIAL' and
ship_name = '$ship_name' and
ship_address = '$ship_address' and
ship_city = '$ship_city' and
ship_state = '$ship_state' and
ship_zip = '$ship_zip' and
ship_country = '$ship_country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$orderid = mysql_result($result, 0, 'orderid');
else
return false;
foreach($HTTP_SESSION_VARS['cart'] as $numb => $quantity)
{
$detail = get_article_details($numb);
$query = "delete from order_items where
orderid = '$orderid' and numb = '$numb'";
$result = mysql_query($query);
$query = "insert into order_items values
('$orderid', '$numb', ".$detail['price'].", $quantity)";
$result = mysql_query($query);
if(!$result)
return false;
}
return $orderid;
}
?> |