I am trying to build hostel booking system. The problem is, I'm getting stuck when it comes to limit of residents for each room.
What I am trying to do is, when the room is limited for 6 residents only, so the 7th person who trying to book will get error message "This room is full. Please book another room."
In this SQL, I want it to read the value of count
, and if it is >=6
, the error message will appear. unfortunately, it wont works
<?php
$result = mysql_query("SELECT COUNT(student_id) AS total FROM booking");
$row = mysql_fetch_row($result);
if (total < 7) {
echo 'We have reached our registration limit';
}
?>
Each room have different capacity of residents, so do I have to apply the SQL for each button?
Here is what I have. Once student click on the button, it will automatically save to database.
<table align="center" width="1100">
<tr valign="baseline">
<td><table cellspacing="0" cellpadding="2" border="1" bordercolor="white" bgcolor="#FFFF99" width="1100" align="center">
<tr>
<th colspan="6" align="center" bgcolor="#CCFFFF"><h3>Block A Room </h3></th>
</tr>
<tr>
<td align="center" width="50"><p>First Floor</p></td>
<td align="center" width="220">
<p>
<form method="POST" name="form1" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="6">A102 </button>
<button name="select_room" type="submit" value="25">A105</button>
</p>
<p>
<button name="select_room" type="submit" value="21">A101 </button>
<button name="select_room" type="submit" value="23">A103 </button>
<button name="select_room" type="submit" value="26">A106 </button>
<button name="select_room" type="submit" value="24">A104 </button>
</p>
</form>
</p> </td>
<td align="center" width="224">
<p>
<form method="POST" name="form2" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="28">A108 </button>
<button name="select_room" type="submit" value="31">A111 </button>
</p>
<p>
<button name="select_room" type="submit" value="27">A107 </button>
<button name="select_room" type="submit" value="29">A109 </button>
<button name="select_room" type="submit" value="32">A112 </button>
<button name="select_room" type="submit" value="30">A110 </button>
</p>
</form>
</p> </td>
<td align="center" width="222">
<p>
<form method="POST" name="form3" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="34">A114 </button>
<button name="select_room" type="submit" value="37">A117 </button>
</p>
<p>
<button name="select_room" type="submit" value="33">A113 </button>
<button name="select_room" type="submit" value="35">A115 </button>
<button name="select_room" type="submit" value="38">A118 </button>
<button name="select_room" type="submit" value="36">A116 </button>
</p>
</form>
</p> </td>
<td align="center" width="222">
<p>
<form method="POST" name="form4" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="40">A120 </button>
<button name="select_room" type="submit" value="43">A123 </button>
</p>
<p>
<button name="select_room" type="submit" value="39">A119 </button>
<button name="select_room" type="submit" value="41">A121 </button>
<button name="select_room" type="submit" value="44">A124 </button>
<button name="select_room" type="submit" value="42">A122 </button>
</p>
</form>
</p> </td>
<td align="center" width="224">
<p>
<form method="POST" name="form5" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="46">A126 </button>
<button name="select_room" type="submit" value="49">A129 </button>
</p>
<p>
<button name="select_room" type="submit" value="45">A125 </button>
<button name="select_room" type="submit" value="47">A127 </button>
<button name="select_room" type="submit" value="50">A130 </button>
<button name="select_room" type="submit" value="48">A128 </button>
</p>
</form>
</p> </td>
</tr>
<tr>
<td align="center" width="50"><p>Ground Floor</p></td>
<td align="center" width="220"><p>
<form method="POST" name="form6" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="2">A002 </button>
<button name="select_room" type="submit" value="4">A004</button>
</p>
<p>
<button name="select_room" type="submit" value="1">A001 </button>
<button name="select_room" type="submit" value="3">A003 </button>
</p>
</form>
</td>
<td align="center" width="224"><p>
<form method="POST" name="form7" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="6">A006 </button>
<button name="select_room" type="submit" value="8">A008 </button>
</p>
<p>
<button name="select_room" type="submit" value="5">A005 </button>
<button name="select_room" type="submit" value="7">A007 </button>
</p>
</form>
</td>
<td align="center" width="222"><p>
<form method="POST" name="form8" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="10">A010 </button>
<button name="select_room" type="submit" value="12">A012 </button>
</p>
<p>
<button name="select_room" type="submit" value="9">A009 </button>
<button name="select_room" type="submit" value="11">A011 </button>
</p>
</form>
</td>
<td align="center" width="222"><p>
<form method="POST" name="form9" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="14">A014 </button>
<button name="select_room" type="submit" value="16">A016 </button>
</p>
<p>
<button name="select_room" type="submit" value="13">A013 </button>
<button name="select_room" type="submit" value="15">A015 </button>
</p>
</form>
</td>
<td align="center" width="224"><p>
<form method="POST" name="form10" action="/turc/student_hostel.php">
<button name="select_room" type="submit" value="18" >A018 </button>
<button name="select_room" type="submit" value="20" >A020 </button>
</p>
<p>
<button name="select_room" type="submit" value="17" >A017 </button>
<button name="select_room" type="submit" value="19">A019 </button>
</p>
</form>
</td>
</table>
</tr>
<tr valign="baseline">
<th>
<input type=button onClick="location.href='/turc/select_block.php'" value='Return' class="myButton">
</th>
</tr>
</table>
Please help me to finish my final project. I am really appreciate it.