insert DOB using html form into database using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • puneetmca
    New Member
    • Jan 2010
    • 15

    insert DOB using html form into database using php

    hi
    i want to insert employees DOB into database through html forms but my code is not working....only empty record is shown in the database in edob ..rest of the records are working properly....... .like ecode,ename etc....i am using date as a datatype in database and my format of date is yy-mm-dd
    i m sending the html and php coding below.
    [code=html] <html>
    <head><title> Employee Data</title></head>
    <body bgcolor="pink">
    <form method="POST" action="empprin s.php">
    <h3> <p align="center"> Employee Personal Detail </h3> </p>
    <table <p align="center">
    <tr> <th>Employee Code :</th><td> <input type="text" name="ecode" size="20"/></td></tr>
    <tr><th>Employe e Name: </th><td><input type="text" name="ename" size="20"/> </td></tr>
    <tr><th> Employee Education:</th><td> <input type="text" name="eedu" size="20"> </td></tr>
    <tr><th> Gender:</th><td> Male<input type="radio" name="egender" value="Male"></td>
    <td> Female<input type="radio" name="egender" value="female"> </td></tr>
    <tr> <th>DOB <td>
    <select size="1" name="edob" value="Year">
    <option>Year</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    <option>2003</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    </select>
    <select size="1" name="edob" value="month"> </th>
    <option>month </option>
    <option>jan</option>
    <option>feb</option>
    <option>mar</option>
    <option>apr</option>
    <option>may</option>
    <option>june</option>
    <option>july</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    <select size="1" name="edob" value="date">
    <option>date</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select> </td></tr>
    <tr><th>Fathe r/Husband Name:</th><td><input type="text" name="ef_hname" size="20"></td></tr>
    <tr><th>Fathe r/Husband Occu:</th><td><input type="text" name="ef_hoccu" size="20"></td></tr>
    <tr><th> Address1:</th><td><textare a rows="2" cols="20" name="eadd1"> </textarea></td></tr>
    <tr><th> Adreess2:</th><td><textare a rows="2" cols="20" name="eadd2" ></textarea></td></tr>
    <tr><th> City </th><td><select size="1" name="ecity" value=""> <BR>
    <option>none</option>
    <option>Ludhian a</option>
    <option>Chandig arh</option>
    <option>Jalandh ar</option>
    <option>Mohal i</option>
    <option>Moga</option>
    <option>Ferozpu r</option>
    <option>Faridko t</option>
    <option>Samrala </option>
    <option>Ambal a</option>
    </select></td></tr>
    <tr><th> State:</th><td><select size="1" name="esta" value="">
    <option>none</option>
    <option>Punja b</option>
    </select></td></tr> <BR>
    <tr><th>Pin No:</th> <td> <input type="text" name="epin" size="20"> </td></tr>
    <tr><th>Conta ct No:</th> <td> <input type="text" name="etel" size="20"> </td></tr>
    </p> </table>
    <input type="submit" value="SAVE">
    </form>
    </body>


    </html>

    [/code]
    [code=php]
    <HTML>
    <HEAD>
    <TITLE>New Document</TITLE>
    </HEAD>
    <BODY>
    <?
    $ecode = $_POST["ecode"];
    $ename = $_POST["ename"];
    $edob =$_POST["edob"];
    $egender=$_POST["egender"];
    $eedu =$_POST["eedu"];
    $ef_hname=$_POS T["ef_hname"];
    $ef_hoccu=$_POS T["ef_hoccu"];
    $eadd1=$_POST["eadd1"];
    $eadd2=$_POST["eadd2"];
    $ecity=$_POST["ecity"];
    $esta=$_POST["esta"];
    $etel=$_POST["etel"];
    $epin=$_POST["epin"];

    $con = mysql_connect(" localhost","roo t","root");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db ("master", $con);

    $query="INSERT INTO emp_personal VALUES ('$ecode','$ena me','$edob','$e gender','$eedu' ,'$ef_hname', '$ef_hoccu','$e add1','$eadd2', '$ecity','$esta ', '$etel','$epin' )";
    if (mysql_query($q uery, $con))
    {
    echo "record added!";

    }
    else
    {
    echo "something went wrong";
    }
    mysql_close($co n)
    ?>
    </BODY>
    </HTML>
    [/code]
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    The first thing I noticed is that you've given the year, month and day (date) select elements the same name (edob). That won't work...

    Name them differently... Maybe edoby, edobm, and edobd respectively.

    Or create and array by naming them: edob[].

    Named separately:
    Code:
    Array
    (
        [edoby] => 1982
        [edobm] => apr
        [edobd] => 8
        [submit] => click
    )
    Named as an array:
    Code:
    Array
    (
        [edob] => Array
            (
                [0] => 1982
                [1] => apr
                [2] => 8
            )
    
        [submit] => click // note: although not mandatory, it's a good habit to name your submit button
    )
    Then construct your dob value for database insertion from there...

    Comment

    • rishab
      New Member
      • Jul 2016
      • 1

      #3
      you could this array code i understand ..but i dont understand which one page i write or includes your code


      please rply shortly

      Comment

      Working...