4

This is pretty basic, but I'm new to web development. I have a form in HTML that takes time and passed it to a variable in PHP script. That works fine. However, I try to now take the date from the user in HTML, and pass it the same way to a variable in PHP and I get nothing (print shows that the variable is empty).

Here is my code:

<form action="" method="post"> <select name="time"> <!-- some values here --> </select> <input type="text" id="datepicker"> <input type="submit"> </form> <?php $search = $_POST['time']; // it prints data print($_POST['time']); // it prints none $search2 = $_POST['datepicker']; print($search2); ?> 

The first print ($search) does print out the time selected by the user. However, the second print ($search2) does not print out the date selected. Where did I go wrong?

1
  • 3
    Try adding a name attribute to your datepicker textbox because you have one in your time select Commented Nov 18, 2015 at 0:07

1 Answer 1

4

Add name to your datepicker:

<input type="text" id="datepicker" name="datepicker"> 

Posted values are accessable via input_name keys, not ids or classes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.