Blueblazer172 Blueblazer172 - 1 month ago 11
MySQL Question

How to fetch data from an select field in php and load into database?

How can i fetch the data from the option-field and load the choosen option-field into the database ?

<div class="form-group col-md-5">
<label class="control-label">Date of birth:*</label>
<div class="form-group">
<div class="col-md-4">
<select type="text" class="form-control" id="day" >
<option>--Day--</option>
<?php
$day = array(range(1,31));
for ($i = 1; $i <= 31; $i++) {
echo "<option name='day'>".$i."</option>";
}
?>
</select>
</div>
<div class="col-md-4">
<select type="text" class="form-control" id="month">
<option>--Month--</option>
<?php
for ($i = 1; $i <= 12; $i++) {
echo "<option name='month'>".$i."</option>";
}
?>
</select>
</div>
<div class="col-md-4">
<select type="text" class="form-control" id="year">
<option>--Year--</option>
<?php
for ($i = 1900; $i <= 2016; $i++) {
echo "<option name='year'>".$i."</option>";
}
?>
</select>
</div>
</div>
</div>


I know i can use https://eonasdan.github.io/bootstrap-datetimepicker/ cause im using bootstrap. but there it's the same. i dont know how to fetch the choosen data.

Answer

I don't know your server side part of code but here you missing values on option fields. This value is what you save in database. So if everything else is okay with your code you should make something like this:

            <label class="control-label">Date of birth:*</label>
            <div class="form-group">
                <div class="col-md-4">
                    <select name="day" type="text" class="form-control" id="day" >
                        <option>--Day--</option>
                        <?php
                           $day = array(range(1,31));
                            for ($dayOfBirth = 1; $dayOfBirth <= 31; $dayOfBirth++) {
                                echo '<option  value="'.$dayOfBirth.'">"'.$dayOfBirth.'"</option>';
                            }
                        ?>
                    </select>
                </div>
                <div class="col-md-4">
                    <select name="month" type="text" class="form-control" id="month">
                        <option>--Month--</option>
                        <?php
                            for ($monthOfBirth = 1; $monthOfBirth <= 12; $monthOfBirth++) {
                                echo '<option  value="'.$monthOfBirth.'">"'.$monthOfBirth.'"</option>';
                            }
                        ?>
                    </select>
                </div>
                <div class="col-md-4">
                    <select name="year" type="text" class="form-control" id="year">
                        <option>--Year--</option>
                        <?php
                            for ($yearOfBirth = 1900; $yearOfBirth <= 2016; $yearOfBirth++) {
                                echo '<option  value="'.$yearOfBirth.'">"'.$yearOfBirth.'"</option>';
                            }
                        ?>
                    </select>
                </div>
            </div>