php 访问mysql数据库验证登录
静态网页代码
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<title>欢迎登录</title>
<body>
<h2>欢迎登录</h2>
<form action="checkLogin.php" method="GET">
用户名:<input type="text" name="uName" value=""/><br>
密码:<input type="password" name="uPassword" value="" /><br>
<input type="submit" value="登录" /><br>
</form>
</body>
</html>
服务器 checkLogin.php 代码
<?php
//用户登录验证$us = $_GET["uName"];
$up = $_GET["uPassword"];
//连接数据库
//1、创建连接 "127.0.0.1"为数据库地址,此例中为本机地址,"root"为数据库用户名,"123456"为数据库密码
$conn = mysql_connect("127.0.0.1","root","123456");
//2、打开数据库 "newsDB"为数据库名
mysql_select_db("newsDB");
//3、sql语句
$sql = "select * from user where userName="".$us."" and password="".$up."";";
//4、执sql语句
$result = mysql_query($sql);
$num = mysql_num_rows($result);
//5、关闭数据库
mysql_close($conn);
//如果返回的不为空,则登录成功
if($num >0){
echo "login ok!!!";
}
else
{
echo "login faile! please try again!";
}
?>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
