php简单登录注册处理

来源:互联网 发布:台湾清华大学知乎 编辑:程序博客网 时间:2024/04/30 18:27

登录页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登录页面</title>
</head>
<body bgcolor="#FCDFE1">
  <form name="loginform" id="loginform" method="post" action="../dao/login.php">
        <table width="408" border="1" align="center">
            <tr>
                <td width="34" height="32">&nbsp;</td>
                <td colspan="2">会员登录:</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td width="83"><div align="right">姓名:</div></td>
                <td width="269"><input type="text" name="username" id="username"/></td>               
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td width="83"><div align="right">密码:</div></td>
                <td width="269"><input type="password" name="password" id="password"/></td>               
            </tr>   
            <tr>
                <td>&nbsp;</td>
                <td width="83"><input type="submit" name="submit1" value="提交"/></td>               
                <td width="83"><input type="reset" name="submit2" value="重置"/></td>                   
            </tr>         
           </table> 
  </form>
</body>
</html>

注册页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册页面</title>
</head>
<body bgcolor="#FCDFE1">
  <form name="registerform" id="registerform" method="post" action="../dao/register.php">
        <table width="408" border="1" align="center">
            <tr>
                <td width="34" height="32">&nbsp;</td>
                <td colspan="2">会员注册:</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td width="83"><div align="right">姓名:</div></td>
                <td width="269"><input type="text" name="username" id="username"/></td>               
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td width="83"><div align="right">密码:</div></td>
                <td width="269"><input type="password" name="password" id="password"/></td>               
            </tr>   
            <tr>
                <td>&nbsp;</td>
                <td width="83"><input type="submit" name="submit1" value="提交"/></td>               
                <td width="83"><input type="reset" name="submit2" value="重置"/></td>                   
            </tr>         
      </table> 
  </form>
</body>
</html>

数据库操作:

注册逻辑:

<?php
  echo "This is the login logical!<br>";
    $username=$_POST['username'];
    $password=$_POST['password'];
    @$db=new mysqli('localhost','root','520123412','wangjin');
    if(mysqli_connect_errno()){
        echo "erro";
        exit;
    }
    $query="insert into userinfo(username,password) values('".$username."', '".$password."');";
    echo "$query<br>";
    $result=$db->query($query);
    if($result){
        echo "register success";       
    }else{
        echo "register fail";
    }
?>

登录逻辑:
<?php
    echo "This is the login logical!<br>";
    $username=$_POST['username'];
    $password=$_POST['password'];
    @$db=new mysqli('localhost','root','520123412','wangjin');
    if(mysqli_connect_errno()){
        echo "erro";
        exit;
    }
    $query="select * from userinfo where username='".$username."' and password='".$password."'";
    echo "$query<br>";
    $result=$db->query($query);
    $row=$result->fetch_row(); 
    if($row){
        echo "login success";       
    }else{
        echo "login fail";
    }
?>

 

 

 

原创粉丝点击