<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="" method="post">
用户名:<input type="text" id="UserName" name="UserName"/>
密码:<input type="password" id="Pwd" name="Pwd"/>
<input type="submit" value="登录" />
<input type="reset" value="重置" />
</form>
</body>
</html>
<?php
//创建到达数据库的连接
$con = mysql_connect("localhost","root","sa");
//如果连接失败
if (!$con)
{
die('连接数据库失败: ' . mysql_error());
}
//成功的话就执行以下代码
if(array_key_exists("UserName", $_POST) && array_key_exists("Pwd", $_POST))
{
mysql_select_db("test", $con);
//mysql_query相当于向数据库发送命令
$sql = mysql_query("SELECT * FROM table_user where user_name = '$_POST[UserName]' and user_password='$_POST[Pwd]'");
if(mysql_num_rows($sql) == 1)
{
echo "<script>alert('登录成功!');location='test6.php';</script>";
}
else
{
echo"<center><font color=red>登录失败!<br/>用户名或密码有错</font></center>";
}
}
//最后要关闭数据库连接
mysql_close($con);
?>
另一边怎么得到用户名显示出来?