I have a function, responsible for knowing if a user made the purchase correctly (complete
) or if the status of the purchase is (incomplete
).
This function is with a single query.
function checkOrderComplete($con,$id_product,$id_user){
$res = false; // the default result
$stmt = $con->prepare("SELECT status FROM order WHERE id_product=? AND id_user=? AND status=? limit 1");
$stmt->bind_param("iis",$id_product,$id_user,$status);
$status='complete';
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows ===1){
$res = true;
} else {
$res = false;
}
return $res;
}
Now I have added a new table called order_details
id_order_product order_date id_product quantity price id_order
1 ----- 2 1 10.00 18
2 ----- 6 1 50.00 18
Order
id_order id_user status
18 3 complete
So what I want to achieve is the same functioning of the function you can realize before, it took into account the status of the purchase if it was completed or not, and the id of the product, and the id of the user who made the purchase.
Then perform the following procedure but it shows me errors in the $stmt->bind_param("isi",$id_user,$status,$id_product);
The query:
$stmt = $con->prepare("SELECT order.status, order.id_user, order_details.id_product FROM order inner join order_details ON order.id_user=? order.status=? order_details.id_product=? LIMIT 1");
How do I obtain the same values mentioned from the two tables?