PHP驗證登陸用戶名和密碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>php

<body>
<form action="duixiangyingyong" method="post">
用戶名:<input type="text" name="user"/><br>
<p></p>
密碼:&nbsp;<input type="text" name="pass"/><br>
<input type="submit" name="sub" value="登陸">
</form>
<?phphtml

if(!isset($_POST['sub']))
{
exit('非法訪問!');
}
else
{
check();
}

function check()
{
$con=mysql_connect("localhost","root","120911");
if(!$con)
{
die('鏈接失敗:'.mysql_error);
}
mysql_select_db("mydb",$con);
$a=$_POST['user'];
$b=$_POST['pass'];
$sql=mysql_query("select*from Persons where FirstName='".$a."'and Age='".$b."'");

$info=mysql_fetch_array($sql);
if($info)
{
echo "<script>alert('登陸成功')</script>>";
}
else
{
echo "<script>alert('登陸失敗')</script>>";
}
}mysql


?>
</body>
</html>sql

相關文章
相關標籤/搜索