
正文
php链接数据库注册账号 php登录注册连接数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP连接myadmin数据库实现登入注册?
你是哪部分不会,数据库连接正常不写好了没?数据库表设计好了没?注册登录页面前端写好了没?用session就可以实现登录了,然后就是你其他页面了,没开发好,可以代开发
相关问答
Q1: php登录页面完整代码连接数据库
创建conn.php,连接数据库。
$dns = 'mysql:host=127.0.0.1;dbname=test';
$username = 'root';
$password = 'root';
// 1.连接数据库,创建PDO对象
$pdo = new PDO($dns,$username,$password);
创建login.html,登陆页面。
用户名
密 码
创建login.php,验证账号密码。
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST["submit"])){
exit("错误执行");
}//检测是否有submit操作
include('conn.php');//链接数据库
$name = $_POST['name'];//post获得用户名表单值
$pwd = sha1($_POST['password']);//post获得用户密码单值
if ($name $pwd){//如果用户名和密码都不为空
$sql = "select * from user where username = '$name' and password='$pwd'";//检测数据库是否有对应的username和password的sql
$stmt = $pdo-prepare($sql);
$stmt-execute();
if($stmt-fetch(PDO::FETCH_BOUND)){//0 false 1 true
header("refresh:0;url=welcome.html");//如果成功跳转至welcome.html页面
exit;
}else{
echo "用户名或密码错误";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";//如果错误使用js 1秒后跳转到登录页面重试;
}
}else{//如果用户名或密码有空
echo "表单填写不完整";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";
//如果错误使用js 1秒后跳转到登录页面重试;
}
$pdo = null;
创建signup.html,注册页面
用户名:
密 码:
创建signup.php
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST['submit'])){
exit("错误执行");
}//判断是否有submit操作
$name=$_POST['name'];//post获取表单里的name
$pwd = sha1($_POST['password']);//post获取表单里的password
include('conn.php');//链接数据库
$sql="insert into user(id,username,password) values (null,'$name','$pwd')";//向数据库插入表单传来的值的sql
$stmt = $pdo-prepare($sql);
$stmt-execute();
$stmt-fetch(PDO::FETCH_BOUND);
if (!$stmt){
die('Error: ' . $stmt-getMessage());//如果sql执行失败输出错误
}else{
echo "注册成功";//成功输出注册成功
}
$pdo = null;//关闭数据库
Q2: php+mysql怎么做登录注册
首先得到提交的数据
链接数据库,查询数据库,查询username 和pwd
提交的username 和 pwd 跟数据库查询的username 和pwd做对比,
都相等那就是登陆成功
?php
mysql_connect('localhost','root','123');
mysql_select_db('lx');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
//数据库lx 表user 字段id username pwd
//用md5加密,可以自己试试
if(isset($_POST['user'])$_POST['tijiao'] == 'success'){
$query = mysql_query("select pwd from user where username = '".$_POST['user']."'");
$num = mysql_num_rows($query);
if($num 0 ){
while($info = mysql_fetch_array($query)){
if($info['pwd'] == md5($_POST['pwd'])){
echo '登陆成功';
}else{
echo '登陆失败';
}
}
}else{
echo '登陆失败';
}
}
?
form action="" method="get"/
table border="0" cellspacing="0" cellpadding="0"
tr
td class="fieldKey" width="30%"用户名:/td
td class="fieldValue" width="100%"input type="text" name="user" //td
/tr
trtd height="10"/td/tr
tr
td class="fieldKey"密码:/td
td class="fieldValue"input type="password" name="pwd" //td
/tr
/table
input type="hidden" name="tijiao" value="success" /
input type="submit" value="登陆"/
/form
Q3: 如何在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='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
Q4: 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());
然后运行一下,看有什么错误提示
Q5: 易语言+PHP+数据库做注册登录程序 怎么做,最好是有教程跟源码!
要是说教程php链接数据库注册账号,没有哪个教程是指定讲哪个问题的,这里面涉及的知识,易语言操作mysql或post或网页填表。教程都很好找。为什么说或,因为常用大概就这三种方法。
直接操作数据库,易语言直接链接网站的数据库,可以不通过php来操作,直接把要注册的帐号写进数据库,这是最直接的方法。
post,首先用httpwatch或其php链接数据库注册账号他抓包工具,抓取注册时的数据包,然后用易语言(精益模块)网页_访问这个方法来进行自制数据包提交。来完成注册。
网页填表,属于在超文本浏览框内打开网站注册页面,然后模拟手动来填写注册信息。
建议使用的方法是post,因为直接操作数据库安全性不高,网页填表每次都要打开一次注册页面,效率不高,建议使用post方法。post视频教程可以找 之乎者也的post教程,关于post的教程有很多
关于php链接数据库注册账号和php登录注册连接数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







