-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
50 lines (44 loc) · 1.85 KB
/
insert.php
File metadata and controls
50 lines (44 loc) · 1.85 KB
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
<?php
include 'connection.php';
if(!null==(filter_input(INPUT_POST, 'submit')))
{
$CustName = $_REQUEST['CustName'];
$orderdate = $_REQUEST['orderdate'];
$item = $_REQUEST['item'];
$thickness = $_REQUEST['thickness'];
$size = $_REQUEST['size'];
$quantity = $_REQUEST['quantity'];
// Insertion to customer table
$sql = "insert into customer(CustName) Values ('".$CustName."')";
$result = mysqli_query($conn,$sql);
// retrieve last customer id
$CustID = $conn->insert_id;
//echo $CustID;die;
$result = '';
// insertion to CustOrder Table
$sql2 = "INSERT INTO custorder (CustID, orderdate) VALUES ('".$CustID."', '".$orderdate."')";
$result2 = mysqli_query($conn,$sql2);
//retrieve last order id
$OrderID = $conn->insert_id;
//mysqli_free_result($result2);
// insertion to Orderitem table
for($i=0;$i<count($_REQUEST['thickness']);$i++){
$sql3 = "INSERT INTO orderitem (OrderID,item, thickness, size, quantity) VALUES(".$OrderID.",'".$_REQUEST['item'][$i]."','".$_REQUEST['thickness'][$i]."','".$_REQUEST['size'][$i]."',".$_REQUEST['quantity'][$i].")";
$result3 = mysqli_query($conn,$sql3);
}
$sql4= "UPDATE product INNER JOIN orderitem ON (product.item = orderitem.item) AND (product.thickness = orderitem.thickness) AND (product.size = orderitem.size)
SET orderitem.ProductID = product.ProductID
WHERE OrderID=".$OrderID."";
$result4 = mysqli_query($conn,$sql4);
if($result4){
echo '<script type="text/javascript">';
echo 'alert("Data Submitted Successfully");';
echo 'window.location = "index.php";';
echo '</script>';
}
else{
echo "ERROR: Could not able to execute. " . mysqli_error($conn);
}
}
$conn->close();
?>