求一个简单的php登录页面代码,只需要用户名和密码与数据库中表里面的信息相同就可以登录的页面代码
1个回答
2016-11-28
展开全部
error_reporting(0);
$mysql_servername = "localhost";
$mysql_username = "数据库用户名";
$mysql_password ="密码";
$mysql_database ="数据库名";
mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);
$name=$_POST['user_name'];
$passowrd=$_POST['user_password'];
if ($name && $passowrd){
$sql = "SELECT * FROM admin WHERE name = '$name' and password='$passowrd'";
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
header("location='主页'");
exit;
}
echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
}else {
echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
}
$mysql_servername = "localhost";
$mysql_username = "数据库用户名";
$mysql_password ="密码";
$mysql_database ="数据库名";
mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);
$name=$_POST['user_name'];
$passowrd=$_POST['user_password'];
if ($name && $passowrd){
$sql = "SELECT * FROM admin WHERE name = '$name' and password='$passowrd'";
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
header("location='主页'");
exit;
}
echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";
}else {
echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>";
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询