01.
<?php
02.
session_start();
03.
04.
$serverName
=
"localhost"
;
05.
$userName
=
"root"
;
06.
$userPassword
=
"12345678"
;
07.
$dbName
=
"mydatabase"
;
08.
09.
$conn
= mysqli_connect(
$serverName
,
$userName
,
$userPassword
,
$dbName
);
10.
if
(!
$conn
) {
11.
echo
$conn
->connect_error;
12.
exit
();
13.
}
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
$Subtotal
=
$_POST
[
"Subtotal"
];
26.
$Balance
=
$_POST
[
"SumTotal"
];
27.
$Received
=
$_POST
[
"Received"
];
28.
$Refund
=
$_POST
[
"Refund"
];
29.
$Credit
=
$_POST
[
"Credit"
];
30.
$Save
=
$_POST
[
"m_name"
];
31.
$Type
=
$_POST
[
"Type"
];
32.
33.
$strSQL
= "
34.
INSERT INTO orders (OrderDate,Balance,Received,Refund,Credit,Save)
35.
VALUES
36.
(
'".date("Y-m-d H:i:s")."'
,
'".$_POST["Balance"]."'
,
'".$_POST["Received"]."'
,
'".$_POST["Refund"]."'
,
'".$_POST["Credit"]."'
,
'".$_POST["Save"]."'
)
37.
";
38.
$objQuery
= mysqli_query(
$conn
,
$strSQL
);
39.
if
(!
$objQuery
)
40.
{
41.
echo
$conn
->error;
42.
exit
();
43.
}
44.
45.
$strOrderID
= mysqli_insert_id(
$conn
);
46.
47.
for
(
$i
=0;
$i
<=(int)
$_SESSION
[
"intLine"
];
$i
++)
48.
{
49.
if
(
$_SESSION
[
"strProductID"
][
$i
] !=
""
)
50.
{
51.
$strSQL
= "
52.
INSERT INTO orders_detail (OrderID,ProductID,Barcode,Qty,Type)
53.
VALUES
54.
(
'".$strOrderID."'
,
'".$_SESSION["strProductID"][$i]."'
,
'".$_SESSION["Barcode"][$i]."'
,
'".$_SESSION["strQty"][$i]."'
,
'".$_POST["Type"][$i]."'
)";
55.
$result
= mysqli_query(
$conn
,
$strSQL
);
56.
if
(!
$result
)
57.
{
58.
echo
$conn
->error;
59.
exit
();
60.
}
61.
else
62.
{
63.
$update
=
"UPDATE producttestqty SET Qty = Qty-'"
.
$_SESSION
[
"strQty"
][
$i
].
"' WHERE Barcode = '"
.
$_SESSION
[
"Barcode"
][
$i
].
"' "
;
64.
mysqli_query(
$conn
,
$update
)
or
die
(mysqli_error(
$conn
));
65.
if
(!
$update
){
66.
echo
$conn
->error;
67.
exit
();
68.
}
69.
}
70.
}
71.
}
72.
73.
mysqli_close(
$conn
);
74.
unset(
$_SESSION
[
'strProductID'
]);
75.
unset(
$_SESSION
[
'strQty'
]);
76.
header(
"location:cusshoworder.php?OrderID="
.
$strOrderID
);
77.
?>