php的用户注册页面,能注册但在数据库显示不了,求各位大神解答,给高分!!
<?phpsession_start();include("admin/conn.php");$name=$_POST[usernc];$pwd1=$_POST[p1];...
<?php
session_start();
include("admin/conn.php");
$name=$_POST[usernc];
$pwd1=$_POST[p1];
$pwd=md5($_POST[p1]);
$email=$_POST[email];
$truename=$_POST[truename];
$sfzh=$_POST[sfzh];
$tel=$_POST[tel];
$qq=$_POST[qq];
if($_POST[ts1]==1)
{
$tishi=$_POST[ts2];
}
else
{
$tishi=$_POST[ts1];
}
$huida=$_POST[tsda];
$dizhi=$_POST[dizhi];
$youbian=$_POST[yb];
$regtime=date("Y-m-j");
$lastlogintime=$regtime;
$logincishu=1;
$ip=getenv("REMOTE_ADDR");
$dongjie=0;
$sql=mysql_query("select * from user where name='".$name."'",$conn);
$info=mysql_fetch_array($sql);
if($info==true)
{
echo "<script>alert('该昵称已经存在!');history.back();</script>";
exit;
}
else
{
mysql_query("insert into user (name,pwd,dongjie,email,truename,sfzh,tel,qq,ip,tishi,huida,dizhi,youbian,regtime,lastlogintime,logincishu,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$ip','$tishi','$huida','$dizhi','$youbian','$regtime','$lastlogintime','$logincishu','$pwd1')",$conn);
$_SESSION['username'] = null;
$username=$name;
$_SESSION['producelist'] = null;
$producelist="";
$_SESSION['quatity'] = null;
$quatity="";
echo "<script>alert('恭喜,注册成功!');window.location='index.php';</script>";
}
?> 展开
session_start();
include("admin/conn.php");
$name=$_POST[usernc];
$pwd1=$_POST[p1];
$pwd=md5($_POST[p1]);
$email=$_POST[email];
$truename=$_POST[truename];
$sfzh=$_POST[sfzh];
$tel=$_POST[tel];
$qq=$_POST[qq];
if($_POST[ts1]==1)
{
$tishi=$_POST[ts2];
}
else
{
$tishi=$_POST[ts1];
}
$huida=$_POST[tsda];
$dizhi=$_POST[dizhi];
$youbian=$_POST[yb];
$regtime=date("Y-m-j");
$lastlogintime=$regtime;
$logincishu=1;
$ip=getenv("REMOTE_ADDR");
$dongjie=0;
$sql=mysql_query("select * from user where name='".$name."'",$conn);
$info=mysql_fetch_array($sql);
if($info==true)
{
echo "<script>alert('该昵称已经存在!');history.back();</script>";
exit;
}
else
{
mysql_query("insert into user (name,pwd,dongjie,email,truename,sfzh,tel,qq,ip,tishi,huida,dizhi,youbian,regtime,lastlogintime,logincishu,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$ip','$tishi','$huida','$dizhi','$youbian','$regtime','$lastlogintime','$logincishu','$pwd1')",$conn);
$_SESSION['username'] = null;
$username=$name;
$_SESSION['producelist'] = null;
$producelist="";
$_SESSION['quatity'] = null;
$quatity="";
echo "<script>alert('恭喜,注册成功!');window.location='index.php';</script>";
}
?> 展开
1个回答
展开全部
你有一处需要优化
2处需要修改
$info=mysql_fetch_array($sql);
if($info==true)
改成
if ( mysql_num_rows($info) )
c错误的地方是:你把session的值全部设置成了null值,其实就是空值!
例外,数据库显示不了,只能说明写入数据库失败,压根就没有写入数据库,你的注册根本就没有成功
mysql_query("insert into user (name,pwd,dongjie,email,truename,sfzh,tel,qq,ip,tishi,huida,dizhi,youbian,regtime,lastlogintime,logincishu,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$ip','$tishi','$huida','$dizhi','$youbian','$regtime','$lastlogintime','$logincishu','$pwd1')",$conn);
改成
mysql_query("insert into user (name,pwd,dongjie,email,truename,sfzh,tel,qq,ip,tishi,huida,dizhi,youbian,regtime,lastlogintime,logincishu,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$ip','$tishi','$huida','$dizhi','$youbian','$regtime','$lastlogintime','$logincishu','$pwd1')",$conn) or die(mysql_error());
然后运行一下,看有什么错误提示
2处需要修改
$info=mysql_fetch_array($sql);
if($info==true)
改成
if ( mysql_num_rows($info) )
c错误的地方是:你把session的值全部设置成了null值,其实就是空值!
例外,数据库显示不了,只能说明写入数据库失败,压根就没有写入数据库,你的注册根本就没有成功
mysql_query("insert into user (name,pwd,dongjie,email,truename,sfzh,tel,qq,ip,tishi,huida,dizhi,youbian,regtime,lastlogintime,logincishu,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$ip','$tishi','$huida','$dizhi','$youbian','$regtime','$lastlogintime','$logincishu','$pwd1')",$conn);
改成
mysql_query("insert into user (name,pwd,dongjie,email,truename,sfzh,tel,qq,ip,tishi,huida,dizhi,youbian,regtime,lastlogintime,logincishu,pwd1) values ('$name','$pwd','$dongjie','$email','$truename','$sfzh','$tel','$qq','$ip','$tishi','$huida','$dizhi','$youbian','$regtime','$lastlogintime','$logincishu','$pwd1')",$conn) or die(mysql_error());
然后运行一下,看有什么错误提示
更多追问追答
追答
警告:mysql_num_rows()预计参数1是资源,空在E:\ WAMP\www \savereg.php上的第29行,未知列'lastlogintime','在“字段列表”
上面这个错误,你仔细看一下,很明显,你的sql语句有错误:
mysql_num_rows()预计参数1是资源,这句说明你的mysql_query()函数没有执行成功,造成这个函数执行不成功,那一般都是sql语句有错误
未知列'lastlogintime','在“字段列表”,这句意思是,没有找到lastlogintime这个字段
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |