<?php

session_start();
require_once 'db_connection.php';

$total_amount = $_POST['total_amount'];
$cusname = $_POST['cusname'];
$user_id = $_SESSION['user_id'];
$today = date('Y-m-d H:i:s');

$sql = "INSERT INTO purchase (q_customer,q_amount, q_user, q_date)
VALUES ('$cusname','$total_amount', '$user_id', '$today')";

if ($conn->query($sql) === TRUE){
	$last_id = $conn->insert_id;
	echo $last_id;
	$sql2 = "UPDATE purchase_items SET qi_no='$last_id' WHERE qi_no=0 AND qi_user='$user_id'";
	if ($conn->query($sql2) === TRUE){		
}
}else{
	echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

?>