This query : payment_date BETWEEN "old date" AND "new date" only success run if we write old date before new date. How to make it work if query payment_date BETWEEN "new date" AND "old date"? Because sometime the user enter new date first, then only enter old date. Example codes :
$sql = "SELECT customer_name, phone_number, address FROM sale
WHERE seller_id=? && $search_by LIKE ? && payment_date BETWEEN ? AND ?";
$q = $conn->prepare($sql);
$result = $q->execute(array($userid, "%".$search_value."%", $oldPaymentDate, $newPaymentDate));
Always validate user input, and at the same time just compare the dates, and do a swap it they are not in the right order, like so: