Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user="root";
- $pass="";
- $host="localhost";
- $dbnamne="neardeal";
- $name = $_REQUEST['name'];
- $user_id = $_REQUEST['user_id'];
- $productStr = $_REQUEST['productIds']; //productIds string separated by ,
- $pricesStr = $_REQUEST['prices']; //productIds string separated by ,
- //create connection
- $conn = new mysqli($host, $user, $pass, $dbnamne);
- //check connection
- if($conn->connect_error){
- die("connection failed" .$com->connect_error);
- }
- $sql = "INSERT INTO orders VALUES(NULL, '$user_id', '$name')";
- $conn->query($sql);
- $order_id = $conn->insert_id;
- $productIds = explode(",", $productStr);
- $prices = explode(",", $pricesStr);
- foreach($productIds as $k=>$productId) {
- $sql = "INSERT INTO item_orders VALUES(NULL, '$order_id', '$productId', '$prices[$k]')";
- $conn->query($sql);
- }
- echo json_encode(array(
- 'success' => true,
- 'order_id' => $order_id
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement