PHP数据库用户注册代码 php写入数据库

求一用php写的注册和登录页面代码reg.php文件
?php
header("Content-type:text/html;charset=utf-8");
if($_POST){
$dsn = 'mysql:dbname=1104javab;host=127.0.0.1';
$user = 'root';
$password = '';
try{
$pdo = new pdo($dsn,$user,$password,array(PDO::MYSQL_ATTR_INIT_COMMAND = 'SET NAMES \'UTF8\'')
);
}catch(Exception $e){
echo '错误'.$e-getmessage();
}
$name = $_POST['name'];
$pwd = md5($_POST['pwd']);
$sql = "insert into 表 (username,password) values ('$name','$pwd')";
$exec = $pdo-query($sql);
if($exec){
echo"scriptalert('成功');location.href='https://www.04ip.com/post/reg.html'/script";
}else{
echo"scriptalert('失败');location.href='https://www.04ip.com/post/reg.html'/script";
}
}
?
reg.html文件
form action='reg.php' method='post'
用户名:input type='text' name='name'
密码:input type='password' name='pwd'
input type='submit' value='https://www.04ip.com/post/submit'
/form
login.html文件
form action='reg.php' method='post'
用户名:input type='text' name='name'
密码:input type='password' name='pwd'
input type='submit' value='https://www.04ip.com/post/submit'
/form
login.php文件
【PHP数据库用户注册代码 php写入数据库】header("Content-type:text/html;charset=utf-8");
if($_POST){
$dsn = 'mysql:dbname=1104javab;host=127.0.0.1';
$user = 'root';
$password = '';
try{
$pdo = new pdo($dsn,$user,$password,array(PDO::MYSQL_ATTR_INIT_COMMAND = 'SET NAMES \'UTF8\'')
);
}catch(Exception $e){
echo '错误'.$e-getmessage();
}
$name = $_POST['name'];
$pwd = $_POST['pwd'];
$sql = "select user_id from 表名 where username='$name' and password='$pwd'";
$stmt = $pdo-query($sql);
$info = $stmt-fetch(PDO::FETCH_ASSOC);
if($info){
echo "登录成功";
}else{
echo "登录失败";
}
}
大概这样
用PHP做一个注册界面的代码?php
$db=mysql_connect("localhost","root","");
$sqlname="MESSAGE";
mysql_select_db($sqlname,$db);
mysql_query("SET NAMES 'gbk'",$db);
if($_POST['tj']){
$username=$_POST['username'];
$password=$_POST['password'];
$conpassword=$_POST['conpassword'];
if($password==$conpassword){
$pwd=$password;
}
else{
echo "scriptalert('两次密码输入不一致');history.back();/script";
}
$sql="insert into MESSAGE(user,password) values('".$username."','".$pwd."')";
$result=mysql_query($sql);
if($result)
{
echo "scriptalert('注册成功');/script";
}
else
{
echo "scriptalert('注册失败);/script";
}
}
?
form method="post" action="#"
p用户名:
input type="text" name="username" id="username"
/p
p密码:
input type="password" name="password" id="password"
/p
p确认密码:
input type="password" name="conpassword" id="conpassword"
/p
p
input type="submit" name="tj" id="tj" value="https://www.04ip.com/post/提交"
input type="reset" value="https://www.04ip.com/post/重置"
/p
/form
php,把注册代码输入到数据库中建立index.php
输入PHP数据库用户注册代码:
form action='reg.php' method='method'
用户名:input type='text' name='uname' /br
密码:input type='password' name='upassword' /br
input type='注册' value='https://www.04ip.com/post/submit' /
/form
保存退出
在相同目录下建立regist.php
输入:
?php
$username=$_POST[uname];//通过POST方法获得提交数据PHP数据库用户注册代码,uname对应index.php中的unamePHP数据库用户注册代码;upassword一样

推荐阅读