首页  >  文章  >  php教程  >  php用户登录实例教程代码

php用户登录实例教程代码

WBOY
WBOY原创
2016-05-25 16:42:38883浏览

这是一款非常简单的php mysql用户登录代码,适合初学者,希望本文章对各位同学会带来帮助,代码如下:

<?php
error_reporting(0);
$mysql_servername = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "peng";
mysql_connect($mysql_servername, $mysql_username, $mysql_password);
mysql_select_db($mysql_database);
$name = $_post[&#39;name&#39;];
$passowrd = $_post[&#39;password&#39;];
if ($name && $passowrd) {
    $sql = "select * from liuyanban where name = &#39;$name&#39; and password=&#39;$passowrd&#39;";
    $res = mysql_query($sql);
    $rows = mysql_num_rows($res);
    if ($rows) {
        header("refresh:0;url=a.htm");
        exit;
    }
    echo "<script language=javascript>alert(&#39;用户名密码错误&#39;);history.back();</script>";
} else {
    echo "<script language=javascript>alert(&#39;用户名密码不能为空&#39;);history.back();</script>";
}
?>
//以下login.htm内容 
 
<html> 
<body> 
<form name="login" action="login.php" method=post> 
用户名<input type=text name="name"> 
<p>密码<input type=password name="password"> 
<p> 
<input name="log" type=submit value="登录"> 
</form> 
</body> 
</html>


文章地址:

转载随意^^请带上本文地址!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn