Home » Php » php – trying to select max invoice id from database

php – trying to select max invoice id from database

Posted by: admin February 25, 2020 Leave a comment


hello i am trying to select max invoice id from a table to get different invoice id everytime customer buy products so i tried this query but i always get 0 in the invoice id

 if (isset($_POST['orderr'])) {

$user = mysqli_query($conn," SELECT * FROM user_account WHERE id='$id'");

$Inv = mysqli_query($conn,"SELECT(isnull((SELECT max (invoice_id) as invoice_id FROM sales),0))+1");

$get = mysqli_query($conn," SELECT * FROM cart WHERE u_id='$id' ");

while ($row=mysqli_fetch_assoc($get)) {

    $price = $row['price'];
    $img = $row['img'];
    $name = $row['name'];
    $qty = $row['qty'];
    $img = $row['img'];

        $insert = mysqli_query($conn, "INSERT INTO sales(customer_name,phone,location,product_name,product_id,price,quantity,sell_date,total,img,invoice_id) VALUES('$fullname','$phone','$location','$name','$p_id','$price','$qty','$date','$total','$img','$invoice')");

        if ($insert) 

        $delete1 = mysqli_query($conn, "DELETE FROM cart WHERE p_id='$p_id' AND u_id='$id'");


other data are inserted well but the invoice id is always 0 can any one help me

How to&Answers: