这是一款非常简单的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['name'];
- $passowrd=$_post['password'];
-
- if ($name && $passowrd){
- $sql = "select * from liuyanban where name = '$name' and password='$passowrd'";
- $res = mysql_query($sql);
- $rows=mysql_num_rows($res);
- if($rows){
- header("refresh:0;url=a.htm");
- exit;
- }
- echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
- }else {
- echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
- }
-
- ?>
-
-
-
- <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>
|