PHP:将外键插入sql DB

时间:2014-04-24 22:17:48

标签: php mysql sql

我有三张桌子:全科医生,病人和约会。 GP和患者的ID也是约会数据库中的外键。我正在为约会表创建一个插入表单,但似乎无法使其工作。它会出现以下错误:"未知列'日期'在'字段列表' "

GP table cols:

GPID,
first_name,
last_name,
surgery_name,
surgery_address,
GP_photo

患者表cols:

PID,
first_name,
last_name,
address,
phone,
P_photo

我的php:

<?php

include("includes/connect.php");

if (isset($_POST['submit'])) {
  $gp = $_POST['GP'];
  $patient = $_POST['patient'];
  $date = $_POST['date'];
  $time = $_POST['time'];
  $outcome = $_POST['outcome'];

  if ($date == '' or $time == '' or $outcome == '') {
    echo "<script>alert('One or more of your fields are blank, "
    . "please ensure you have entered content in ALL fields.')</script>";
  } else {

    $insert_query = "insert into appointments (GPID,PID,date,time,outcome)"
            . " values('$gp','$patient','$date','$time','$outcome')";

    mysql_query($insert_query);
  }
}
?> 

我的表格:

<form action="appointments.php" method="post">
  <table>
    <tr>
      <td>GP:</td>
      <td><select name="GP">
          <?php
          include("includes/connect.php");
          $GP_list = mysql_query("SELECT GPID, first_name, last_name FROM GPs");
          while ($row = mysql_fetch_array($GP_list)) {
            echo'<option value="' . $row['GPID'] . '">' . $row['GPID'] . 
                    ': ' . $row['first_name'] . ' ' . $row['last_name'] . 
                    '</option>';
          }
          ?>
        </select>
      </td>
    </tr>
    <tr>

      <td>Patient:</td> 
      <td><select name="patient">
          <?php
          include("includes/connect.php");
          $P_list = mysql_query("SELECT PID, first_name, last_name FROM patients");
          while ($row = mysql_fetch_array($P_list)) {
            echo'<option value="' . $row['PID'] . '">' . $row['PID'] . 
                    ': ' . $row['first_name'] . ' ' . $row['last_name'] . 
                    '</option>';
          }
          ?>
        </select>
      </td>
    </tr>

    <tr>
      <td>Date:</td> 
      <td><input type="date" name="date"></td>
    </tr>

    <tr>
      <td>Time:</td> 
      <td><input type="time" name="time"></td>
    </tr>

    <tr>
      <td>Outcome:</td>
      <td><textarea rows="8" cols="40" name="outcome"></textarea>
        <input type="submit" name="submit" value="Book appointment"></td>
    </tr>
  </table>
</form>

0 个答案:

没有答案
相关问题