daz daz - 7 months ago 26
MySQL Question

How to process input value from HTML form in PHP to insert into MySQL query?

Consider this HTML fragment (which will run a PHP script as the form action):

<label class="form-label" for="dateOfBirth">Date of birth</label>
<input type="date" id="dob" class="field date-field dob-field"
min="1900-01-01" max="2016-12-31" required>


How can I get back the value of this date input in my PHP script to insert it into a MySQL query?

Answer

Add 'name' attribute then use it in php $_POST.

<input type="date" id="dob" name="exdate" class="field date-field dob-field" min="1900-01-01" max="2016-12-31"  required>

In php, you can get this by

$exdate=$_POST['exdate'];

Then use it in mysq query

WHERE columnname='$exdate'