01.
<?php
02.
session_start();
03.
$sid
= session_id();
04.
include
"storescripts/connect_to_mysql.php"
;
05.
$sql
=
"SELECT * FROM cart WHERE sid = '$sid';"
;
06.
$result_cart
= mysql_query(
$sql
);
07.
if
(mysql_num_rows(
$result_cart
) == 0) {
08.
die
(
"ท่านไม่เลือกสินค้าไว้ในรถเข็น"
);
09.
}
10.
11.
$firstname
=
""
;
12.
$lastname
=
""
;
13.
$address
=
""
;
14.
$zipcode
=
""
;
15.
$phone
=
""
;
16.
$email
=
""
;
17.
$payment
=
""
;
18.
$errmsg
=
""
;
19.
if
(
$_POST
) {
20.
21.
foreach
(
$_POST
as
$k
=>
$v
) {
22.
if
(
empty
(
$v
)) {
23.
$errmsg
=
"ท่านยังใส่ข้อมูลไม่ครบ"
;
24.
break
;
25.
}
26.
$v
=
stripslashes
(
$v
);
27.
$v
= htmlspecialchars(
$v
, ENT_QUOTES);
28.
29.
$_POST
[
$k
] =
$v
;
30.
}
31.
32.
}
33.
$firstname
=
$_POST
[
'firstname'
];
34.
$lastname
=
$_POST
[
'lastname'
];
35.
$address
=
$_POST
[
'address'
];
36.
$zipcode
=
$_POST
[
'zipcode'
];
37.
$phone
=
$_POST
[
'phone'
];
38.
$email
=
$_POST
[
'email'
];
39.
$payment
=
$_POST
[
'payment'
];
40.
41.
if
(
$errmsg
==
""
) {
42.
$sql
= "INSERT INTO members VALUES
43.
(0,
'$firstname'
,
'$lastname'
,
'$address'
,
'$zipcode'
,
'$phone'
,
'$email'
,
'$payment'
);";
44.
45.
@mysql_query(
$sql
)
or
die
(mysql_error());
46.
47.
$cid
= mysql_insert_id();
48.
49.
$sql
=
"SELECT * FROM cart WHERE sid = '$sid';"
;
50.
$result
= mysql_query(
$sql
);
51.
52.
while
(
$cart
= mysql_fetch_array(
$result
)) {
53.
$pid
=
$cart
[
'pid'
];
54.
$product_name
=
$cart
[
'product_name'
];
55.
$price
=
$cart
[
'price'
];
56.
$quantity
=
$cart
[
'quantity'
];
57.
$sql
= "INSERT INTO order VALUES
58.
(0,
'$cid'
,
'$pid'
,
'$product_name'
,
'$price'
,
'$quantity'
);";
59.
60.
@mysql_query(
$sql
)
or
die
(mysql_error());
61.
}
62.
63.
$sql
=
"DELETE FROM cart WHERE sid = '$sid';"
;
64.
@mysql_query(
$sql
)
or
die
(mysql_error());
65.
66.
if
(
$_POST
[
'save_cookie'
]) {
67.
$expire
= time() + 12*30*24*60*60;
68.
setcookie(
'firstname'
,
$_POST
[
'firstname'
],
$expire
);
69.
setcookie(
'lastname'
,
$_POST
[
'lastname'
],
$expire
);
70.
setcookie(
'address'
,
$_POST
[
'address'
],
$expire
);
71.
setcookie(
'zipcode'
,
$_POST
[
'zipcode'
],
$expire
);
72.
setcookie(
'phone'
,
$_POST
[
'phone'
],
$expire
);
73.
setcookie(
'email'
,
$_POST
[
'email'
],
$expire
);
74.
75.
}
76.
}
77.
else
if
(
$_COOKIE
) {
78.
$firstname
=
$_COOKIE
[
'firstname'
];
79.
$lastname
=
$_COOKIE
[
'lastname'
];
80.
$address
=
$_COOKIE
[
'address'
];
81.
$zipcode
=
$_COOKIE
[
'zipcode'
];
82.
$phone
=
$_COOKIE
[
'phone'
];
83.
$email
=
$_COOKIE
[
'email'
];
84.
}
85.
?>