Home > php教程 > php手册 > body text

php用户登录实例教程代码

WBOY
Release: 2016-05-25 16:42:38
Original
887 people have browsed it

这是一款非常简单的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>
Copy after login


文章地址:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template