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

PHP连接myadmin数据库实现登入注册?你是哪部分不会,数据库连接正常不写好了没?数据库表设计好了没?注册登录页面前端写好了没?用session就可以实现登录了,然后就是你其他页面了,没开发好,可以代开发
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='https://www.04ip.com/post/login.html';},1000);
";//如果错误使用js 1秒后跳转到登录页面重试;
}
}else{//如果用户名或密码有空
echo "表单填写不完整";
echo "
setTimeout(function(){window.location.href='https://www.04ip.com/post/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;//关闭数据库
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 usernamepwd
//用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($num0 ){
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

推荐阅读