求大神帮忙写一个php的验证用户登录
<formaction="login.php"method="post">用户名:<inputtype="text"name="user">密码:<inputtype="...
<form action="login.php" method="post">
用户名:<input type="text" name="user">
密码:<input type="password" name="pass">
<input type="submit" value="登陆后台">
</form>
HTML文件代码这样,求大神帮忙写一下php的代码!
mysql数据库名是select,表名是test,用户名是user,密码是pass 展开
用户名:<input type="text" name="user">
密码:<input type="password" name="pass">
<input type="submit" value="登陆后台">
</form>
HTML文件代码这样,求大神帮忙写一下php的代码!
mysql数据库名是select,表名是test,用户名是user,密码是pass 展开
2个回答
展开全部
给你个以前做好的吧
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
session_start();
$coon_ = "localhost";
$name_ = "root";
$password_="root";
$error_ = "无法连接数据库1,请重来";
$conn=mysql_connect($coon_,$name_,$password_) or die($error_);
mysql_select_db("select")
or die($error_);
mysql_query("SET NAMES 'gbk'");//解决汉字
if($_POST){
$username = $_REQUEST['username'];
$pass = $_REQUEST['password'];
$sql =" SELECT * FROM test where user = '$username' and pass = '$pass'";
$r = mysql_query($sql);
if(!empty($r)){
$row = mysql_fetch_assoc($r);
$dl_mima=$row[pass];
$_SESSION['yhm']=$username;
echo "<script>alert('成功登陆')</script>";
echo "<script>window.location.href='index.php';</script>";
}else{
echo "<script>alert(\"您输入的用户名或者密码错误,请重新输入!\")</script>";
}
}
?>
<form id="form2" name="form2" method="post" action="">
<table width="452" height="148" border="1" align="center">
<tr>
<td><p>
<font color=red>用户名:</font>
<input name="username" type="text" id="username" />
</p>
<p>
<font color=red>密 码:</font>
<input name="password" type="password" id="password" />
</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p></td>
</tr>
</table>
</form>
展开全部
$db=mysql_connect(连接你的数据库); mysql_select_db('login', $db); $u=$_POST['u']; $p=$_POST['p']; if($u && $p){ $query=mysql_query('select * from exam where name=\''.$u.'\'',$db); if($re=mysql_fetch_array($query,MYSQL_ASSOC)&&$re['password']==$p){ exit('<script>alert(\'登陆成功\');history.back();</script>'); }else{ exit('<script>alert(\'用户名不存在,或密码错误\');history.back();</script>'); } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询