0

私は2つのテーブルを持っています:reservations_client そしてtables_clients

reservation_clientは 3 つのフィールドがあります。

idname_clientdatetable

table_clientsは 2 つのフィールドがあります。

idname_table

クライアントが予約したいときは、名前と日付を入力してテーブルを選択しますが、問題があります.2人のクライアントが同じテーブルを使用することはできません.

必要なのは、日付が異なる場合にのみデータベースにデータを挿入することです。日付が同じ場合 (つまり、誰かが既にテーブルを使用している場合)、エラーが送信されます。

一意のキーを使用しようとしましたが、日付が異なっていてもエラーが発生します。

私のPHPコード:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO reservations_clients (user, number_person, table, date) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['user'], "text"),
                       GetSQLValueString($_POST['number_person'], "int"),
                       GetSQLValueString($_POST['table'], "int"),
                       GetSQLValueString($_POST['date'], "text"),

  mysql_select_db($database_conexionbdd, $conexionbdd);
  $Result1 = mysql_query($insertSQL, $conexionbdd) or die(mysql_error());

mysql_select_db($database_conexionbdd, $conexionbdd);
$query_table = "SELECT * FROM tables";
$table = mysql_query($query_table, $conexionbdd) or die(mysql_error());
$row_table = mysql_fetch_assoc($table);
$totalRows_tables = mysql_num_rows($table);

クライアントが入力するフォームは次のとおりです。

      <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
          <tr valign="baseline">
            <td nowrap align="right">Number_person:</td>
            <td><input type="text" name="Number of persons" value="" size="32"></td>
          </tr>
          <tr valign="baseline">
            <td nowrap align="right">table:</td>
            <td><select name="numero_mesa">
              <?php
do {  
?>
              <option value="<?php echo $row_table['idtable']?>" <?php if (!(strcmp($row_tables['idtable'], $row_table['idtable']))) {echo "SELECTED";} ?>><?php echo $row_table['name_table']?></option>
              <?php
} while ($row_table = mysql_fetch_assoc($table));
?>
            </select></td>
          <tr>
          <tr valign="baseline">
            <td nowrap align="right">date:</td>
            <td><input type="text" name="fecha"  size="32" id="datepicker" /></td>

          </tr>
<tr>          
  <td nowrap align="right">&nbsp;</td>
            <td><input type="submit" value="Enviar"></td>
          </tr>
        </table>
        <input type="hidden" name="user" value="<?php echo $row_user['user']; ?>">
        <input type="hidden" name="MM_insert" value="form1">
      </form>
      <p>&nbsp;</p>
4

4 に答える 4