0

i have a database at the links.
so the problem it still insert between the time some friends suggested to loop all the data 1st
then validate but im confused here.
**any help would be great **

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
<?php 
mysql_connect("localhost","root","");
mysql_select_db("windsor_reservation");

if(isset($_POST['reserve'])){

       echo  $stime = ($_POST['stime']);
       echo  '----';
       echo  $etime = ($_POST['etime']);
       echo  '<br>';
       $chk = false;
     $date = date("Y-m-d");
    if($stime < $etime){
     $q = mysql_query("SELECT * FROM time WHERE `date`='$date' AND `stime`>='$stime' AND `etime`<='$etime'");
     $count =  mysql_num_rows($q);
          if($count > 0){
        echo 'Time already taken choose another time please';
      }else{
       $new_all = mysql_query("SELECT * FROM time where date='$date'");
            while($get_all = mysql_fetch_assoc($new_all)){
              echo   $g_all_stime = $get_all['stime'];   
              echo  "====";
              echo   $g_all_etime = $get_all['etime'];
                echo "<br>";       
                if($stime == $g_all_stime && $etime == $g_all_etime){
                    echo 'There is already a time like yours';
                    $chk = false;

                }
                elseif($stime <= $g_all_stime && $etime >= $g_all_etime){
                    echo 'cannot insert the same Start and End time with server';
                    $chk = false;

                }
                elseif($stime > $g_all_stime && $etime < $g_all_etime){
                    echo 'the time must not be between the earlier reserve time';
                     $chk = false;
                }
                elseif($etime >= $g_all_stime && $stime <= $g_all_etime){
                    echo 'the end time must not be the same as the start time and the end time must not 
                    be the same with the end time';
                    $chk = false;
                }
                else{
                    echo 'ELSE no other choice insert here';
                    $chk = true;
                }
            }
            if($chk == true){
                echo "insert there";
                mysql_query("INSERT INTO time(date,stime,etime)values('$date','$stime','$etime')");
            }else{
                echo "break the statement";
            }

      }

     } else{
     echo 'do not insert';
 }     
 }           
?>
        <form method="post">

            start<input type="time" name="stime">
            end<input type="time" name="etime"><br>
            <input type="submit" name="reserve" value="reserve">
        </form>
    </body>
</html>
Attachments table.png 14.68 KB database.png 49.47 KB
2
Contributors
4
Replies
32
Views
3 Years
Discussion Span
Last Post by joshuajames.delacruz
-1

could this be a dtetime format issue? I would echo all the values to see how they compare

0

Solved it

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
<?php 
mysql_connect("localhost","root","");
mysql_select_db("windsor_reservation");

if(isset($_POST['reserve'])){

       echo  $stime = ($_POST['stime']);
       echo  '----';
       echo  $etime = ($_POST['etime']);
       echo  '<br>';
     $date = date("Y-m-d");
      if($stime < $etime){
     $q = mysql_query("SELECT * FROM time WHERE date='$date' AND stime>='$stime' AND etime<='$etime'");
     $arr_query = mysql_fetch_assoc($q);
     $count =  mysql_num_rows($q);
          if($count > 0){
        echo 'Time already taken choose another time please';
      }else{
       $new_all = mysql_query("SELECT * FROM time where date='$date'");
            while($get_all = mysql_fetch_assoc($new_all)){
              echo   $g_all_stime = $get_all['stime'];       
              echo   $g_all_etime = $get_all['etime'];
                echo "<br>";       
                if($stime == $g_all_stime && $etime == $g_all_etime){
                    echo 'There is already a time like yours';  

                    break;
                }
                elseif($stime <= $g_all_stime && $etime >= $g_all_etime){
                    echo 'cannot insert the same Start and End time with server';
                     break;

                }
                elseif($stime >= $g_all_stime && $etime <= $g_all_etime){
                    echo 'the time must not be between the earlier reserve time';
                     break;

                }
                elseif($etime >= $g_all_stime && $stime <= $g_all_etime){
                    echo 'the end time must not be the same as the start time and the end time must not 
                    be the same with the end time';
                    break;
                }
                else{
                    echo 'ELSE no other choice insert here';
                    echo "<br>";
                    echo mysql_query("INSERT INTO time(date,stime,etime)values('$date','$stime','$etime')");
                    break;
                }
            }
      }
      }
      else{
     echo 'do not insert';
 }

 }


?>
        <form method="post">

            start<input type="time" name="stime">
            end<input type="time" name="etime"><br>
            <input type="submit" name="reserve" value="reserve">
        </form>
    </body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.