注册表单的年月日怎么添加到数据库呢?下拉菜单的出生日期,如何放到数据库呢??我在出生日期那定义的名字不对,接受表单的名字是 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.'> '.$start_year.' </option>';
}
echo '</select>'.'年';
//月
echo '<select name = month >';
for($start_month = 1; $start_month <= 12; $start_month++){
echo '<option value ='.$start_month.' >'.$start_month.' </option>';
}
echo '</select>'.'月';
//日
echo '<select name = day >';
for($start_day = 1;$start_day <= 31 ;$start_day++){
echo '<option value ='. $start_day.' >'.$start_day.' </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"){
}
<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.'> '.$start_year.' </option>';
}
echo '</select>'.'年';
//月
echo '<select name = month >';
for($start_month = 1; $start_month <= 12; $start_month++){
echo '<option value ='.$start_month.' >'.$start_month.' </option>';
}
echo '</select>'.'月';
//日
echo '<select name = day >';
for($start_day = 1;$start_day <= 31 ;$start_day++){
echo '<option value ='. $start_day.' >'.$start_day.' </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"){
}
解决方案 »
- php网站开发中使用递归的例子有哪些?能否提供实例代码。谢谢
- 请问如果在 html下怎样直接输出数据
- PHP连不上MYSQL急!!!!!!!!
- 求助:文件上传出错,在线等!
- PHP如何调用C函数接口?
- php中如何调用函数?简单吧
- -----------300分求源代码:文件上传--------------
- "select gif from table" gif为"binary"类型的字段。出现"Php 发生错误(PHP_MSSQL70.DLL)。Php即将关闭。如果仍有问题,请尝试重新启动计算机。
- php多个表查询的问题
- select显示
- PHP的小留言板,删除语句不管用~
- 菜鸟求一个preg_replace问题
月:$_POST['year']
日:$_POST['year']
后台这样就可以获取了。需要什么格式自己组合就是了!
年:$_POST['year']
月:$_POST['month']
日:$_POST['day']
直接 inset就可以
<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.'> '.$start_year.' </option>';
}
echo '</select>'.'年';
//月
echo '<select name = "month" >';
for($start_month = 1; $start_month <= 12; $start_month++){
echo '<option value ='.$start_month.' >'.$start_month.' </option>';
}
echo '</select>'.'月';
//日
echo '<select name = "day" >';
for($start_day = 1;$start_day <= 31 ;$start_day++){
echo '<option value ='. $start_day.' >'.$start_day.' </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 "注册失败,请重新填写";
}
}