I run the following query to check if a student has already booked an event to stop them re-booking by disabling the 'Book Now' button via the following SQL with PDO & HTML:
// Existing Booking check to disable Booking button if required:
$bookingcount=0;
$countsql = "SELECT Count(BookingId) FROM tblBookings WHERE tblBookings.UserId=? AND tblBookings.EventId=?";
$countquery = $dbh -> prepare($countsql);
$countquery->execute([$userid,$eid]);
$bookingcount = intval($countquery->fetchColumn());
<button type="button" <?php echo $bookingcount > 0 ? 'disabled="true"' : ''; ?> class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Book Now</button></div>
I used echo of the Userid & EventID on both localhost and server and they always show the correct values.
On localhost if there was an existing booking then $bookingcount echoes as 1 otherwise 0 so disabling the button when required.
On the hosted server it always returns zero even when there is an existing booking. The Userid is retrieved from a session variable and the eid is passed in. Both always show as the correct values on the localhost or server environment via echo.
I added the table-name as prefixes in the query as another similar problem mentioned on here was fixed by the prefixing but not in this case.
No other query is giving me problems and this is the only Select Count(*) being used - Is there a special case for counting rows that different environments causes this type of error?
I know when i coded the select count via PDO I had to research it as there were lots of people making conflicting comments on how it should be done...
Any pointers is much appreciated
Thanks Martin