I am designing a web page and for storing the data i am using the form method.
<form method="POST" action="filldata.php">
<div><input type="date" name="calendar" id="datesetter" name="selectdate"></div>
<div><select id="mySelect" onchange="myFunction()" name="selectslot" >
<option value="-----">Time Slot
<option value="9to11">9 to 11
<option value="11to1">11 to 1
<option value="2to4">2 to 4
</select></div>
<input type="text" placeholder="Enter Name" id="ename" name="ename" class="alignleft" >
<div><select id="mySelectbranch" onchange="myFunction3()" name="branch" >
<option value="-----">Select Department
<option value="b1">Computer Engineering
<option value="b2">Mechanical Engineering
<option value="b3">Electrical Engineering
<option value="b4">Electronics & Telecommunication Engineering
<option value="b4">Information Technology
</select></div>
<div><select id="mySelectaudi" onchange="myFunction2()" name="auditorium" class="alignright" >
<option value="-----">Select Auditorium
<option value="audi1">Audi 1- Block A
<option value="audi2">Audi 2- Block A
<option value="audi3">Audi 3- Block B
</select></div>
<input type="submit" value="Book Auditorium" id="book" onclick="book();" name="submit" >
</form>
php code:
<?php
require "menu.php";
function NewUser($conn)
{
$date=$_POST['selectdate'];
$time = $_POST['selectslot'];
$name = $_POST['ename'];
$dept = $_POST['branch'];
$audi = $_POST['auditorium'];
$data = "INSERT INTO bookings (date,timeslot,name,dept,audino) VALUES ('$date','$time','$name','$dept','$audi')";
$result=mysqli_query($conn,$data);
}
it consists of few input boxes (text boxes(input type=text)) and a date picker(input type=date). so when submit button is clicked all data is stored except that of date
that field remains blank. All other text variables are stored in database.
it gives this notice:
Notice: Undefined index: selectdate in..........
What I have tried:
I thought this was because you cannot send date type via post method to php or maybe php cannot directly store date type via post method.
i browsed and used this line instead:
$date=date('d/m/Y', strtotime(str_replace('.', '-',$_POST['selectdate'])));
but then the date which was stored in database was 01/01/1970 , i tried few different methods but every time it was of type 1970/01/01