每间客房预订限6人

时间:2015-05-23 20:50:50

标签: php html sql

我正在尝试建立宿舍预订系统。问题是,当涉及每个房间的居民限制时,我会陷入困境。

我想要做的是,当房间仅限6名居民时,所以第7个尝试预订的人将收到错误消息"这个房间已满。请预订另一个房间。"

在此SQL中,我希望它读取count的值,如果它是>=6,则会显示错误消息。不幸的是,它不会起作用

 <?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';
}
?>

每个房间都有不同的居民容量,所以我是否必须为每个按钮应用SQL?

这就是我所拥有的。学生点击按钮后,会自动保存到数据库。

<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>
        &nbsp;
        <button name="select_room" type="submit" value="4">A004</button>
          </p>
      <p>
        <button name="select_room" type="submit" value="1">A001 </button>
        &nbsp;
        <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>
        &nbsp;
        <button name="select_room" type="submit" value="8">A008 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="5">A005 </button>
        &nbsp;
       <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>
        &nbsp;
        <button name="select_room" type="submit" value="12">A012 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="9">A009 </button>
        &nbsp;
       <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>
        &nbsp;
        <button name="select_room" type="submit" value="16">A016 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="13">A013 </button>
        &nbsp;
       <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>
        &nbsp;
        <button name="select_room" type="submit" value="20" >A020 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="17" >A017 </button>
        &nbsp;
       <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>

请帮我完成我的最终项目。我真的很感激。

1 个答案:

答案 0 :(得分:0)

 <?php 
$result = mysql_query("SELECT COUNT(student_id) AS total FROM booking");
$row = mysql_fetch_object($result);
$total =$row->total;
if ($total > 6) { 
    echo 'We have reached our registration limit';
}
?>