Omar Faruk Omar Faruk - 1 month ago 8
PHP Question

How to insert date value in database

This is my html code. I am trying to insert a date value in a database but I can't see it how it is possible.

<select name="date">
<option value="selected"> Day </option>
<option value="1">1</option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
</select>

<select name="date">
<option value="selected"> Month </option>
<option value="jan"> jan </option>
<option value="feb"> feb </option>
<option value="mar"> mar </option>
<option value="april"> april </option>
</select>

<select name="date">
<option value="selected"> year </option>
<option value="1990"> 1990 </option>
<option value="1991"> 1991 </option>
<option value="1992"> 1992 </option>
<option value="1993"> 1993 </option>
</select>

Answer

It's very easy just use serialize() and unserialize(). and also [] this array sign in you name like it . here is example:

<select name="date[]">
                    <option value="selected"> Day </option>
                    <option value="1">1</option>
                    <option value="2"> 2 </option>
                    <option value="3"> 3 </option>
                    <option value="4"> 4 </option>
                </select> 

                <select name="date[]">
                    <option value="selected"> Month </option>
                    <option value="jan"> jan </option>
                    <option value="feb"> feb </option>
                    <option value="mar"> mar </option>
                    <option value="april"> april </option>
                </select> 

               <select name="date[]">
                    <option value="selected"> year </option>
                    <option value="1990"> 1990 </option>
                    <option value="1991"> 1991 </option>
                    <option value="1992"> 1992 </option>
                    <option value="1993"> 1993 </option>
                </select>

and add this name key in serialize() function and unserialize your database value using unserialize() function.

insert

 $date = serialize($_POST['date']);

View

$date = unserialize($date);
            echo $date[0]."/ ".$date[1]."/ ".$date[2];
Comments