learnerX
learnerX

Reputation: 1082

Why can't I get HTML form to pass values to PHP?

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?

Upvotes: 4

Views: 2086

Answers (1)

userlond
userlond

Reputation: 3818

Add name to your datepicker:

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

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

Upvotes: 4

Related Questions