Problem
I am trying to calculate if there is a registration with the same phone number and date. This is to ensure that people do not register two reservations on the same date (time). My problem is that I expect the query to return
0 , because there is no registration with the same data in the database. The result, however, is
1 . This would mean that the database already has something like that, but no. I assume that it is associated with a request that I am executing before the current request. I wonder if I should close the expression.
What i tried
I tried to close the expression
$stmt->close() , but to no avail. I tried to create new variables instead of reusing those from the previous query, but that didn't work either. I triple checked the database to make sure there is no registration with the same details, and I am 100% sure that there is nothing wrong with the database.
Code
Here is my code. I think the problem lies in the first part of the request.
$query = "SELECT count(*) as reservation_amount FROM reservation WHERE `date`= ?"; $stmt = $db->prepare($query); $stmt->bind_param("s", $datetime); $stmt->execute(); $stmt->bind_result($count); while($row = $stmt->fetch()){ $res_count = $row;
Enter
datetime = 2014-12-28 17:00:00 number = 0612345678
Database
The database contains the following entry:
id name surname number email date amount 5 Henk Houtman 9060666 henk@houtman.nl 2014-12-28 17:00:00 1
No mistakes.
source share