php表单提交用session保存问题
<?phpsession_start();//判断是否POST提交了nameif(isset($_POST['name'])){$_SESSION['name']=$_P...
<?php
session_start();
//判断是否POST提交了name
if (isset($_POST['name'])) {
$_SESSION['name']=$_POST['name'];
}
?>
<?php
include("dll.php");
$name=$_POST['name'];
if($_POST['submit']){
$name=$_POST['name'];
$sql="select * from zcyh where name='$name'";
$res=mysql_query($sql);
$row=mysql_fetch_assoc($res);
if($row['name']!=$name){
$sql="insert into zcyh (name,password,sex,age,date) values ('$_POST[name]',md5('$_POST[password]'),'$_POST[sex]','$_POST[age]',now())";
mysql_query($sql);
header("Location:zccg.php");
}else {
echo "对不起,你输入的用户名已经存在!<br/><br/>";
$url=$_SERVER['HTTP_REFERER'];
echo "<a href='index.php'>返回</a>";
}
exit(); //还没完成判断是否为空时的操作
}
?>
<!DOCTYPE table PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<h3><font color="#96449b"><center>注册帐号</center></font></h3><br/>
<hr color="#3f7f7f" align="left">
<form acticn="zcyh.php" method="post">
昵称:<input type="text" name="name"/><br/><br/><!-- //在input里加上 readonly="readonly",可以让这个框里变成只读-->
密码:<input type="password" name="password"/><br/><br/>
<?php
echo "年龄:<select name='age'/>";
for($i=18;$i<61;$i++){
echo "<option value='$i'>$i</option>";
}
echo "</select><br/>";
?>
<br/>
性别:<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女<br/>
<br/><br/>
<center><input type="submit" value="确认注册" name="submit"/><a href="index.php">返回首页</a></center>
</form>
</html> 展开
session_start();
//判断是否POST提交了name
if (isset($_POST['name'])) {
$_SESSION['name']=$_POST['name'];
}
?>
<?php
include("dll.php");
$name=$_POST['name'];
if($_POST['submit']){
$name=$_POST['name'];
$sql="select * from zcyh where name='$name'";
$res=mysql_query($sql);
$row=mysql_fetch_assoc($res);
if($row['name']!=$name){
$sql="insert into zcyh (name,password,sex,age,date) values ('$_POST[name]',md5('$_POST[password]'),'$_POST[sex]','$_POST[age]',now())";
mysql_query($sql);
header("Location:zccg.php");
}else {
echo "对不起,你输入的用户名已经存在!<br/><br/>";
$url=$_SERVER['HTTP_REFERER'];
echo "<a href='index.php'>返回</a>";
}
exit(); //还没完成判断是否为空时的操作
}
?>
<!DOCTYPE table PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<h3><font color="#96449b"><center>注册帐号</center></font></h3><br/>
<hr color="#3f7f7f" align="left">
<form acticn="zcyh.php" method="post">
昵称:<input type="text" name="name"/><br/><br/><!-- //在input里加上 readonly="readonly",可以让这个框里变成只读-->
密码:<input type="password" name="password"/><br/><br/>
<?php
echo "年龄:<select name='age'/>";
for($i=18;$i<61;$i++){
echo "<option value='$i'>$i</option>";
}
echo "</select><br/>";
?>
<br/>
性别:<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女<br/>
<br/><br/>
<center><input type="submit" value="确认注册" name="submit"/><a href="index.php">返回首页</a></center>
</form>
</html> 展开
展开全部
恩好,下班先,回家后帮你解决
追问
好的,谢谢你了哈
追答
<?php
session_start();
if (isset($_POST['name'])) {
include("dll.php");
$name = $_POST['name'];
$sql="select * from zcyh where name='$name'";
$res = mysql_query($sql);
if($res && mysql_num_rows($res)){//查询有数据
echo "对不起,你输入的用户名已经存在!<br/><br/>";
$url=$_SERVER['HTTP_REFERER'];
echo "<a href='index.php'>返回</a>";
exit();
}else{//没有数据
$sql="";//添加用户
mysql_query($sql);
$_SESSION['name'] = $name;
//其他操作
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="">
昵称:<input type="text" name="name"/><br/><br/>
密码:<input type="password" name="password"/><br/><br/>
年龄:
<select name="age" id="">
<?php
for ($i=18; $i <= 60; $i++) {
echo "<option value='$i'>$i</option>";
}
?>
</select><br/><br/>
性别:<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女<br/><br/>
<input type="submit" value="确认注册" name="submit"/>
</form>
</body>
</html>
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询