php链接数据库注册账号 php登录注册连接数据库( 二 )


tr
td class="fieldKey"密码:/td
td class="fieldValue"input type="password" name="pwd" //td
/tr
/table
input type="hidden" name="tijiao" value="https://www.04ip.com/post/success" /
input type="submit" value="https://www.04ip.com/post/登陆"/
/form
如何在PHP里 进入注册页面后打上资料点提交然后数据填入数据库里 等于注册了一个账号以下是简单示例:
html
head
title注册示例/title
/head
body
form method='post' action='test.php'
table bgcolor='#cccccc'
tr
tdEmail address:/td
tdinput type='text' name='email' size=30 maxlength=100/td/tr
tr
tdPreferred username br /(max 16 chars):/td
td valign='top'input type='text' name='username'
size=16 maxlength=16/td/tr
tr
tdPassword br /(between 6 and 16 chars):/td
td valign='top'input type='password' name='passwd'
size=16 maxlength=16/td/tr
tr
tdConfirm password:/td
tdinput type='password' name='passwd2' size=16 maxlength=16/td/tr
tr
td colspan=2 align='center'
input type='submit' value='https://www.04ip.com/post/Register'/td/tr
/table/form
?php
//连接数据库
function db_connect()
{
$result = new mysqli('localhost', 'test', 'password', 'test');
if (!$result)
return false;
return $result;
}
//注册用户资料到数据库
function register($username, $email, $password)
{
// connect to db
$conn = db_connect();
//检查用户名是否唯一
$result = $conn-query("select * from user where username='$username'");
if (!$result)
throw new Exception('无法搜索数据库');
if ($result-num_rows0)
throw new Exception('该用户名已经存在,请检查后重试!');
// 如果通过,则写入数据库
$result = $conn-query("insert into user values
('$username', sha1('$password'), '$email')");
if (!$result)
throw new Exception('无法写入数据库,请稍候重试');
return true;
}
$email=$_POST['email'];
$username=$_POST['username'];
$passwd=$_POST['passwd'];
$passwd2=$_POST['passwd2'];
register($username, $email, $passwd);
?
/body
/html
PHP注册不了 , 可以连接数据库,sql放入数据库正常使用,就是无法在页面注册!你有一处需要优化
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());
然后运行一下,看有什么错误提示
易语言+PHP+数据库做注册登录程序 怎么做,最好是有教程跟源码!要是说教程php链接数据库注册账号,没有哪个教程是指定讲哪个问题的,这里面涉及的知识,易语言操作mysql或post或网页填表 。教程都很好找 。为什么说或,因为常用大概就这三种方法 。
直接操作数据库 , 易语言直接链接网站的数据库 , 可以不通过php来操作,直接把要注册的帐号写进数据库,这是最直接的方法 。

推荐阅读