PHP约会->不应该进行注册的时间。.我缺少什么?

时间:2019-03-07 11:42:24

标签: php

因此,基本上,我想预约医生,如果他/她想在同一日期和同一时间与另一位患者去看同一位医生,我不想注册该患者。 这是我的PHP代码:

$con2 = mysqli_connect('localhost','root','','cabinet');

$sql="SELECT data,ora,doctorul FROM programare";
  $res2=mysqli_query($con2,$sql);
  while($row=mysqli_fetch_array($res2)){
    $data2=$row['data'];
    $ora2=$row['ora'];
    $doctor2=$row['doctorul'];
  }

if (isset($_POST['programare'])) {
  $errors=array();
  $nume=$_POST['nume'];
  $data=$_POST['data'];
  $ora=$_POST['ora'];
  $tip=$_POST['tip'];
  $doctor=$_POST['doctor'];

if(!empty($nume) && !empty($data) && !empty($ora) && !empty($doctor)){
  if ($data == $data2 && $ora == $ora2 && $doctor == $doctor2) {
    array_push($errors,"Programare existenta la acea ora!");
  }else{
        $sql2="INSERT INTO programare(nume,data,ora,tipul,doctorul)VALUES(?,?,?,?,?)";
        mysqli_query($con2,$sql2);
        $stmt = mysqli_stmt_init($con2);
         if(!mysqli_stmt_prepare($stmt,$sql2)){
         echo "SQL error";
          } else {
          mysqli_stmt_bind_param($stmt,"sssss",$nume,$data,$ora,$tip,$doctor);
         mysqli_stmt_execute($stmt);
        }
        array_push($errors,"Programare inregistrata");
  }
}else{
      array_push($errors,"Introduceti toate datele!");
    }

}

因此,如果我在date1 hour1将pacient1注册到Doctor1,之后我想在date1 hour1将pacient2注册到Doctor1,则它不会注册pacient2,但是如果我在date2 hour2之后注册了pacient3到Doctor2,在date1 hour1将pacient4注册到doctor1上,它起作用了……不应该……所以我的代码中缺少什么?

这是表格:

<form class="form-horizontal form-bordered" method="post">
                    <?php  include('erori.php');  ?>
                  <div class="form-group">
                    <label class="col-md-3 control-label" for="inputFocus">Nume</label>
                    <div class="col-md-6">
                      <input class="form-control" id="inputFocus" type="text" name="nume" autocomplete="off">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-md-3 control-label" for="inputFocus">Tip</label>
                    <div class="col-md-6">
                      <input class="form-control" id="inputFocus" type="text" name="tip" autocomplete="off">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-md-3 control-label" for="inputFocus">Data</label>
                    <div class="col-md-6">
                      <input class="form-control" id="datepicker2" type="text" name="data" autocomplete="off">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-md-3 control-label" for="inputFocus">Ora</label>
                    <div class="col-md-6">
                      <input class="form-control" id="inputFocus" type="text" name="ora" autocomplete="off">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-md-3 control-label">Doctor</label>
                    <div class="col-md-6">
                      <select data-plugin-selectTwo class="form-control populate" name="doctor">
                        <option></option>
                         <?php 
                             $con = mysqli_connect('localhost','root','','cabinet');

                             $sql="SELECT user FROM users WHERE level='1'";
                             $res=mysqli_query($con,$sql);
                              while($row=mysqli_fetch_array($res)){
                                 echo "<option>".$row['user']."</option>";
                              }

                              ?>
                      </select>
                    </div>
                  </div>

                  <div class="form-group" id="btnform">
                         <button type="submit" class="mb-xs mt-xs mr-xs btn btn-primary" name="programare">Inregistrare</button>
                  </div>
                </form>

0 个答案:

没有答案