I'm having a trouble of inserting my date & time in my database. I used jquery datepicker and for the time I used a select options tag so I just need them to be inserted into the database. This is my date table:
DATABASE:
CREATE TABLE
date_tbl(
datevarchar(30) NOT NULL,
timevarchar(30) NOT NULL,
ordertypeint(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
HTML:
<div class="col-md-4">
<h5 class="control-label" style="font-family:Lucida Calligraphy;margin-left: -15px">Date:</h5>
<input type="text" name="datepicker" class="form-control" placeholder='Select date' id="datepicker" style="margin-left: -15px"/>
<script>
$(function() {
$('#datepicker').datepicker({
minDate: 0,
dateFormat: 'yy-mm-dd'
});
});
</script>
</div>
<div class="col-md-4">
<h5 for="inputDate" class="control-label" style="font-family:Lucida Calligraphy;margin-left: -15px">Time: </h5>
<select type="text" name="time" id="time" class="form-control">
<option>Select time</option>
<option>08:00 AM</option>
<option>09:00 AM</option>
<option>10:00 AM</option>
<option>11:00 AM</option>
<option>01:00 PM</option>
<option>02:00 PM</option>
<option>03:00 PM</option>
<option>04:00 PM</option>
<option>05:00 PM</option>
</select>
</div>
PHP:
<?php
include('db.php');
if(isset($_POST['reserve'])){
$wdate = $_POST['datepicker'];
$wtime = $_POST['time'];
$wdate_array = array();
$wtime_array = array();
$insertDate=$conn->query("INSERT INTO date_tbl (date, time, ordertype) VALUES ('$wdate','$wtime',0)");
$q=$conn->query("SELECT * FROM date_tbl");
$dateRow=mysqli_num_rows($q);
while($row=mysqli_fetch_array($q)){
$wdate_array[]=$row['date'];
$wtime_array[]=$row['time'];
}
if(array_intersect($wdate_array, $wtime_array)){
echo "<p style='text-align:center;color:red;'><span class='fa fa-warning'></span> Date & Time Invalid!</p>";
}else{
echo "<p style='text-align:center;color:green;'><b></b> Date & Time are available!</p>";
}
}
?>
whenever i try to reserve it will only insert once and when i try again it doesn't insert anymore.