鑫雨
2013-10-26加入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 对数据库操作没有太多基础,经过两步最简单的验证字段是否存在操作,实现验证用户名密码是否匹配。 服务器端checklogin.asp 代码如下: <!--#include file="Connections/connuser.asp" --> '数据库连接代码存放在Connections/connuser.asp <% codepage="65001" mail=Replace(request.querystring("email"),"'","") '获取表单中邮箱 mima=Replace(request.querystring("password"),"'","") '获取表单中密码 sql1="select * from [user] where [email]='"&mail&"'" '从user表中查询邮箱 sql2="select * from [user] where [email]='"&mail&"' and [password]='"&mima&"'" '查询邮箱和密码 rs.Open sql1,conn,1,1 '数据库连接查询 if rs.eof or rs.bof then '邮箱为查到 response.write "1" '返回1 else '查到邮箱,下面代码查邮箱和密码 rs.close '先关闭数据库连接,否则 rs.Open sql2,conn,1,1 无法建立 rs.Open sql2,conn,1,1 if rs.eof or rs.bof then '若找不到记录 response.write "2" '返回2 else '找到记录,表示邮箱密码匹配 response.write "0" '返回0 end if end if rs.close %> connuser.asp 代码: <% codepage="65001" ' FileName="Connection_ado_conn_string.htm" ' Type="ADO" ' DesigntimeType="ADO" ' HTTP="true" ' Catalog="" ' Schema="" set rs = Server.CreateObject("adodb.recordset") set conn = Server.CreateObject("ADODB.Connection") Dim MM_connuser_STRING MM_connuser_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.Mappath("./djgjeigxigi15980/kdjgiegj128490.mdb") conn.Open MM_connuser_STRING %> html代码(代码中登录按钮的type属性应为button而不是submit,否则页面会刷新): <%@LANGUAGE="VBSCRIPT"%> <!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> <style type="text/css"> #top-1{ position: fixed; top: 0; left: 0; padding-bottom: 1px; width: 100%; height: 40px; background-color:#666; background:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#666)); } #top-1-1{ width:960px; height:40px; margin:0 auto; text-align:left; font-size:20px; } #denglu{ width:600px; display: block; height: 37px; margin:0; padding:3px 5px; line-height: 33px; color: #000; overflow: visible;} #container{ margin:15px auto; width:958px; height:900px; border:1px solid #CCC; } #tishi{ padding:0px; font-size:14px; font-weight:600; color:#FF0000; } </style> <script type="text/javascript" language="javascript"> function checklogin(){ var mail=document.getElementByIdx_x("email").value; var mima=document.getElementByIdx_x("password").value; var tishi=document.getElementByIdx_x("tishi"); var xmlhttp=false; //邮箱为空提示输入邮箱。 if(mail=="") { tishi.innerHTML="请输入邮箱"; denglu.style.width="625px"; } //邮箱不为空,用ajax发送获取表单数据 else { try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { xmlhttp=new XMLHttpRequest(); } catch (e) { } } } xmlhttp.open("get","checklogin.asp?email="+escape(mail)+ "&password="+escape(mima)+"&t=" + new Date().getTime()); xmlhttp.setRequestHeader("content-type","text/xml"); xmlhttp.setRequestHeader("If-Modified-Since","0"); xmlhttp.onreadystatechange=function() { if(4==xmlhttp.readyState) { if(200==xmlhttp.status) { if (xmlhttp.responseText=="1") { tishi.innerHTML="邮箱不正确"; denglu.style.width="625px"; } else if (xmlhttp.responseText=="2") { tishi.innerHTML="密码错误"; denglu.style.width="625px"; } else { tishi.innerHTML=xmlhttp.responseText; } } else { tishi.innerHTML=xmlhttp.responseText; denglu.style.width="630px"; } } } xmlhttp.send(null); return false; } } </script> </head> <body> <div id="top-1" > <div id="top-1-1" > <div id="denglu"> <form id="f-login" name="f-login" > <label for="email">邮箱:</label><input name="email" id="email" type="email" padding:0px; size="12" " /> <label for="password">密码:</label><input name="password" id="password" type="password" size="12" /> <span id="tishi"></span> <input type="button" style="padding:5px 8px 5px 10px;font-size:14px; font-weight:600;cursor:pointer;" name="login" id="login" value="登录" onclick="checklogin()"/> <a href="#" target="_blank" style="padding:5px 8px 5px 10px;font-size:14px; font-weight:600;cursor:pointer;">注册</a> <a href="#" target="_blank" style="font-size:14px">找回密码</a> </form> </div></div> </div> <div id="container"> </div> </body> </html> |
目前还没有评论