首先得到提交的数据
链接数据库,查询数据库,查询username 和pwd
提交的username 和 pwd 跟数据库查询的username 和pwd做对比,
都相等那就是登陆成功
<?phpmysql_connect('localhost','root','123')
mysql_select_db('lx')
mysql_query("SET CHARACTER SET utf8")
mysql_query("SET NAMES utf8")
//数据库lx 表user 字段id username pwd
//用md5加密,可以自己试试
if(isset($_POST['user'])&&$_POST['tijiao'] == 'success'){
$query = mysql_query("select pwd from user where username = '".$_POST['user']."'")
$num = mysql_num_rows($query)
if($num > 0 ){
while($info = mysql_fetch_array($query)){
if($info['pwd'] == md5($_POST['pwd'])){
echo '登陆成功'
}else{
echo '登陆失败'
}
}
}else{
echo '登陆失败'
}
}
?>
<form action="" method="get"/>
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<td class="fieldKey" width="30%">用户名:</td>
<td class="fieldValue" width="100%"><input type="text" name="user" /></td>
</tr>
<tr><td height="10"></td></tr>
<tr>
<td class="fieldKey">密码:</td>
<td class="fieldValue"><input type="password" name="pwd" /></td>
</tr>
</table>
<input type="hidden" name="tijiao" value="success" />
<input type="submit" value="登陆"/>
</form>
仅仅修改你的loginok.asp页面源代码:<!--#include file="conn.asp"-->
修改为:<!-- #Include virtual="\conn.asp"-->
user=Replace(Request.Form("user"),"'","''")
修改为:user=Request("user")
pwd=Replace(Request.Form("pwd"),"'","''")
修改为:pwd=Request("pwd")
sql="select * from user where user='"&user&"' and pwd='"&pwd&"'"
修改为:sql="select * from user where user='" &user &"' and pwd='" &pwd &"'"
(注意:“"”号和“&”之间必须有空格!)
在<%end if%>的后面直接语句:
<%rs.close
set rs=nothing%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)