Click here to Skip to main content
15,886,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 12-Mar-18 11:14am
v2
Comments
ZurdoDev 12-Mar-18 16:25pm    
Of course php can store dates so click Improve question and show more of the code so people can see what you did wrong.
chinu1d 12-Mar-18 16:30pm    
i have updated and added my code. can you check it now?
Afzaal Ahmad Zeeshan 12-Mar-18 16:25pm    
That is not the type, it is a value. The default value if you do not pass the actual value for the date.

1 solution

Get rid of the secondary name in the field? 'name="calendar" ... name="selectdate"'
 
Share this answer
 
Comments
Maciej Los 12-Mar-18 17:47pm    
5ed!
David O'Neil 12-Mar-18 17:59pm    
Thx, although all it was in this case was being a second set of eyes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900