r/PHPhelp • • Oct 09 '17

Checking for availability between dates

So basically I am to make a reservation system for a resort. I have already made a database: https://imgur.com/f9aLyFZ. I really need to know how to check if dates are available when making a reservation.

So far I did this: $sql = "SELECT * FROM room_type_tbl

    INNER JOIN room_tbl ON room_type_tbl.room_type_id=room_tbl.room_type_id

    WHERE room_type_tbl.room_capacity='$roomcap' && ('$datein'>booking_tbl.checkin_date && '$dateout'<booking_tbl.checkoutdate)
";

if ($conn->query($sql) === TRUE) {
    //echo "Table MyGuests created successfully";
} else {
  echo "Error creating table: " . $conn->error;
}

It's not working and I'm about to go mad. Please help me.

8 Upvotes

7 comments sorted by

View all comments

3

u/pablojohns Oct 09 '17 edited Oct 10 '17

Side note: please tell me you’re not storing the full card number and expiration in this database in plaintext. The fact that the field is for an integer is very concerning.

Please consider using a 3rd party payment processor as this is asking for MAJOR trouble, not just for the client but for your reputation as well. Cards should be run once through a processor for an authorization, and then kept securely on file WITH THE PROCESSOR, not in a database with the full card number, expiration, and customer billing info.

3

u/Dr_Midnight Oct 10 '17

While we're on the subject, increase the size of the email address column, and the password column. varchar(20) and varchar(30) are way too small for both columns respectively.

2

u/[deleted] Oct 10 '17

This

A good length of password hash is equal to the length of a nice hash. PHP has a nice hashing function built in for a while, so use that, and then let users put in a password of any length.