如何避免重复订单ID

I am facing a problem with possible duplicate order id, if submit at the same time.
May I know how to fully solve this problem or avoid it happened?

Below is my code showing how I am getting order ID and send it to database

<?php

                $sqlt = "SELECT ORD_ID FROM tpointgroup WHERE Group_ID = '$tid'";
                $order = mysqli_query($conn , $sqlt);
                $rowcount = mysqli_num_rows($order);
                if ($rowcount == 0)
                    echo "No records found";        
                else 
                {
                    $rowt = mysqli_fetch_assoc($order);
                }
                $ordid = $rowt["ORD_ID"] + 1;
?>

 $ORD_ID = date('ym').str_pad($tkid, 6, '0', STR_PAD_LEFT);

$insert = "insert into cusinfo (ORD_ID) values ('$ORD_ID')";
$insert3 = "UPDATE tpointgroup SET 
    ORD_ID = '$ordid' 
    WHERE Group_ID = $tid ";

I take order ID from tpointgroup table, because I want to know what is the current order ID and add 1 to it.
When user click submit, the order ID will be assign to the customer and update the current orderID to the table tpointgroup.
But something is going wrong in my system with duplicate order id, if two or more users submit at the same time, the order id of customer will be same.

Try the following to generate unique order id.

$order_id = time() . mt_rand() . $tid;