注册表单的年月日怎么添加到数据库呢?下拉菜单的出生日期,如何放到数据库呢??我在出生日期那定义的名字不对,接受表单的名字是 borndate  注册表单的代码:<html>
<head>
<title>用户注册</title>
<style>
body{
font-size:14px;
background:white;
text-align:center;
}
table{
margin:0 auto;
width:500px;
}
th{

text-align:right;
line-height:40px;
}
.a{
width:250px;
}
</style>
</head>
<body>
<p><caption><h1>用户注册</h1></caption></p>
<table border="0">
<form action="action.php?a=add" method="post">

<tr>
<th>*用户名:</th><td><input class="a" type="text" name="username" value=""></td>
</tr>
<tr>
<th>*密码:</th><td><input class="a"  type="password" name="password" value=""></td>
</tr>
<tr>
<th>*重复密码:</th><td><input class="a"  type="password" name="password" value=""></td>
</tr>
<tr>
<th>*性别:</th>
<td>
<input id="aa" type="radio" checked name="sex" value="1"><label for="aa">男</label>
<input id="bb" type="radio" name="sex" value="2"><label for="bb">女</label>
<input id="cc" type="radio" name="sex" value="0"><label for="cc">保密</label>
</td>
</tr>
<tr>
<th>*出生年月:</th>
<td>
<?php
//年
echo '<select name = year >';
                         for($start_year = 2011; $start_year >= 1900; $start_year--){
                                 echo '<option value ='.$start_year.'>&nbsp;'.$start_year.'&nbsp;</option>';
                         }
                         echo '</select>'.'年';

//月
echo '<select name = month >';
                         for($start_month = 1; $start_month <= 12; $start_month++){
                                echo '<option value ='.$start_month.'&nbsp;>'.$start_month.'&nbsp;</option>';
                         }
                         echo '</select>'.'月';
                        
//日
echo '<select name = day >';
                         for($start_day = 1;$start_day <= 31 ;$start_day++){
                                 echo '<option value ='. $start_day.'&nbsp;>'.$start_day.'&nbsp;</option>';
                         }
                         echo '</select>'.'日';
?>
</td>
</tr>
<tr>
<th>*email:</th><td><input class="a"  type="text" name="email" value=""></td>
</tr>
<tr>
<th>*来自:</th><td><input class="a"  type="text" name="comefrom" value=""></td>
</tr>
<tr>
<th>*职位:</th><td><input class="a"  type="text" name="job" value=""></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="sub" value="注册">
<input type="reset" name="reset" value="重写">
</td>
</tr>
</form>
</table>
</body>
</html>
添加到数据库代码:<?php
require "conc.inc.php";
if($_GET["a"] == "add"){
$sql = "INSERTY INTO zhuce(username, password, sex, email, comefrom, job) VALUES('{$_POST["username"]}','{$_POST["password"]}','{$_POST["sex"]}','{$_POST["email"]}','{$_POST["comefrom"]}','{$_POST["job"]}')";
$result = mysql_query($sql);
if($result && mysql_affected_rows() > 0){
header("Location:form.php");
}else{
header("Location:action.php");
}
}else if($_GET["a"]=="mod"){

}
 

解决方案 »

  1.   

    年:$_POST['year']
    月:$_POST['year']
    日:$_POST['year']
    后台这样就可以获取了。需要什么格式自己组合就是了!
      

  2.   

    上面写错了,修正一下:
    年:$_POST['year']
    月:$_POST['month']
    日:$_POST['day']
      

  3.   

    $nyr=$_POST['year']."-".$_POST['month']."-".$_POST['day'];
    直接 inset就可以
      

  4.   

    我合到一起了,可是这样注册不了,哪里错了呢?<html>
    <head>
    <title>用户注册</title>
    <style>
    body{
    font-size:14px;
    background:white;
    text-align:center;
    }
    table{
    margin:0 auto;
    width:500px;
    }
    th{

    text-align:right;
    line-height:40px;
    }
    .a{
    width:250px;
    }
    </style>
    </head>
    <body>
    <p><caption><h1>用户注册</h1></caption></p>
    <table border="0">
    <form action="form.php" method="post">

    <tr>
    <th>*用户名:</th><td><input class="a" type="text" name="username" value=""></td>
    </tr>
    <tr>
    <th>*密码:</th><td><input class="a"  type="password" name="password" value=""></td>
    </tr>
    <tr>
    <th>*重复密码:</th><td><input class="a"  type="password"  value=""></td>
    </tr>
    <tr>
    <th>*性别:</th>
    <td>
    <input id="aa" type="radio" checked name="sex" value="1"><label for="aa">男</label>
    <input id="bb" type="radio" name="sex" value="2"><label for="bb">女</label>
    <input id="cc" type="radio" name="sex" value="0"><label for="cc">保密</label>
    </td>
    </tr>
    <tr>
    <th>*出生年月:</th>
    <td>
    <?php
    //年
    echo '<select name = "year" >';
                             for($start_year = 2011; $start_year >= 1900; $start_year--){
                                     echo '<option value ='.$start_year.'>&nbsp;'.$start_year.'&nbsp;</option>';
                             }
                             echo '</select>'.'年';

    //月
    echo '<select name = "month" >';
                             for($start_month = 1; $start_month <= 12; $start_month++){
                                    echo '<option value ='.$start_month.'&nbsp;>'.$start_month.'&nbsp;</option>';
                             }
                             echo '</select>'.'月';
                            
    //日
    echo '<select name = "day" >';
                             for($start_day = 1;$start_day <= 31 ;$start_day++){
                                     echo '<option value ='. $start_day.'&nbsp;>'.$start_day.'&nbsp;</option>';
                             }
                             echo '</select>'.'日';
    ?>
    </td>
    </tr>
    <tr>
    <th>*email:</th><td><input class="a"  type="text" name="email" value=""></td>
    </tr>
    <tr>
    <th>*来自:</th><td><input class="a"  type="text" name="comefrom" value=""></td>
    </tr>
    <tr>
    <th>*职位:</th><td><input class="a"  type="text" name="job" value=""></td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <input type="submit" name="sub" value="注册">
    <input type="reset" name="reset" value="重写">
    </td>
    </tr>
    </form>
    </table>
    </body>
    </html><?php
    if(isset($_POST["sub"])){
    $borndate=$_POST['year']."-".$_POST['month']."-".$_POST['day'];
    $sql = "INSERT INTO zhuce(username,password,sex,borndate,email,comefrom,job) VALUES('{$_POST["username"]}','{$_POST["password"]}','{$_POST["sex"]}','$borndate','{$_POST["email"]}','{$_POST["comefrom"]}','{$_POST["job"]}')";
    $result = mysql_query($sql);
    if($result && mysql_affected_rows() > 0){
    echo "注册成功";
    }else{
    echo "注册失败,请重新填写";
    }
    }