0

I'm coding a hotel management system and I have this error:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /storage/ssd4/268/9399268/public_html/functions.php:106

Stack trace: #0 /storage/ssd4/268/9399268/public_html/bookIt.php(31): Functions->checkForValidationHotel('hotel-5d5ad4027...', '2019-8-26', '2019-8-29', '8')

1 {main} thrown in /storage/ssd4/268/9399268/public_html/functions.php on line 106

public function checkForValidationHotel($booked_uid,$booking_start,$booking_end,$booking_count)
    {
        $start = $booking_start;
        $end = $booking_end;
        $start = new DateTime($start);
        $end   = new DateTime($end);
        $days = $start->diff($end)->format('%a');
        $current_date = $booking_start;
        $booked = 0;
        $query = $this->con->prepare("SELECT * FROM hotels WHERE uid = ?");
        $query->bind_param("s",$booked_uid);
        $query->execute();
        $data = $query->get_result()->fetch_assoc();
        $query->close();
        $main_count = $data['rooms_left'];


        if ($booking_count > $main_count){
            return false;
        } else {
            for ($i = 0; $i <= $days;){

                if ($current_date == $booking_end){
                    return true;
                    break;
                }
                $stmt = $this->con->prepare("SELECT * FROM ? WHERE uid = ?");
                $stmt->bind_param("ss" , $current_date,$booked_uid);
                $stmt->execute();
                $req_data = $stmt->get_result()->fetch_assoc();
                $stmt->close();
                $count = $req_data['book_count'];
                $booked  =  $count + $booked;
                $rem = $main_count - $booked;
                if ($rem < $booking_count){
                    return false;
                }else{
                    $current_date =  date('Y-m-d', strtotime($current_date . ' +1 day'));
                    $i++;

                }

            }

        }

    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Kmaangaty
  • 83
  • 1
  • 12
  • 1
    prepare fails -> $stmt is false, because tablename can't be "?" (and I doubt the table is called after $current_date smth like 20190826) – Jeff Aug 26 '19 at 21:22
  • The two links I posted should give you an answer why you get this error. – Dharman Aug 26 '19 at 21:23
  • 3
    If you have a table-per-date type thing going on here you're making a mistake in terms of relational database design. You need one table with a date column. MySQL can handle billions of rows so I doubt you'll be overloading that table with bookings any time soon. – tadman Aug 26 '19 at 21:25

0 Answers0