10/10/2018, 09:27
Giúp mình lập trình web với asp
Mình đang làm đề tài kết thúc môn học LT Web với asp. Mình làm tới phần login hoài mà vẫn không làm được. Mình copy code cho các bạn xem có chổ nào sai thì góp ý giúp mình nhe.
***********đoạn code của phần login.asp ****************
<%if session("suserid")>0 then
response.redirect("myaccount.asp")
elseif session("suserid")=-1 then
msg="Wrong Password"
elseif session("suserid")=-2 then
msg="Invalid Username"
else
msg="Please enter your Username and Password."
end if
%>
<html>
<head>
<title>Welcome to JavaScript </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function checkInput()
{
if (document.frmLogin.txtUser.value=="")
{
alert(" Please enter your own UserName");
document.frmLogin.txtUser.focus();
return false;
}
if (document.frmLogin.txtPWD.value=="")
{
alert("Please enter your own Password");
document.frmLogin.txtPWD.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<div class="text_header">
Login User</div>
<br>
<div class="text_header">
<%=msg%>
</div>
<br>
<table>
<form name="frmLogin" method="post" action="test.asp" onsubmit="return checkInput();">
<tr>
<td align="left" class="content-sm">
Username:</td>
</tr>
<tr>
<td align="left" class="input">
<input type="text" name="txtUser" size="25" maxlength="100" class="textbox">
</td>
</tr>
<tr>
<td align="left" class="content-sm">
Password:</td>
</tr>
<tr>
<td align="left" class="input">
<input type="text" name="txtPWD" size="25" maxlength="8" class="textbox">
</td>
</tr>
<tr>
<td align="left" class="text_normal" valign="top">
<br />
<input type="submit" style="width:80px" name="Signin" value="Sign me in!" class="button">
<input type="reset" name="Reset" value="Reset" class="button">
</td>
</tr>
</form>
</table>
</body>
</html>
*******************đoạn code của trang logincheck.asp*******************
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Page 1</title>
</head>
<body>
<%dim strConn
strConn="Provider=SQLOLEDB.1;Persist Security Info=False;UID=sa;PWD=;Initial Catalog=QLCH ;Server=192.168.0.172"%>
<%
session.codepage=65001
strsql="select * from nhanvien where username='"& request.form("txtUser")&"'"
dim conn,rst
set conn=createobject("ADODB.connection")
set rst=createobject("ADODB.recordset")
conn.open strconn
rst.open strsql,conn
if not rst.EOF then
if rst("password")=request.form("txtPWD") then
response.redirect("adduser.htm")
else
response.redirect("login.asp")
end if
else
response.redirect("login.asp")
end if
set conn=nothing
set rst=nothing
%>
<table>
<tr><td> <%=rst("hoten")%></td></tr>
<tr><td> <%=rst("password")%></td></tr>
</table>
</body>
</html>
mình nghĩ nó sai ở chổ này : if rst("password")=request.form("txtPWD")
cái đoạn rst("password") không lấy được dữ liệu từ CSDL SQL nên khi so sánh với request.form("txtPWD") chắc chắn không trùng nhau. Các bạn có kinh nghiệm làm web vui lòng hướng dẫn mình khắc phục lỗi này. Mình xin cám ơn.
***********đoạn code của phần login.asp ****************
<%if session("suserid")>0 then
response.redirect("myaccount.asp")
elseif session("suserid")=-1 then
msg="Wrong Password"
elseif session("suserid")=-2 then
msg="Invalid Username"
else
msg="Please enter your Username and Password."
end if
%>
<html>
<head>
<title>Welcome to JavaScript </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function checkInput()
{
if (document.frmLogin.txtUser.value=="")
{
alert(" Please enter your own UserName");
document.frmLogin.txtUser.focus();
return false;
}
if (document.frmLogin.txtPWD.value=="")
{
alert("Please enter your own Password");
document.frmLogin.txtPWD.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<div class="text_header">
Login User</div>
<br>
<div class="text_header">
<%=msg%>
</div>
<br>
<table>
<form name="frmLogin" method="post" action="test.asp" onsubmit="return checkInput();">
<tr>
<td align="left" class="content-sm">
Username:</td>
</tr>
<tr>
<td align="left" class="input">
<input type="text" name="txtUser" size="25" maxlength="100" class="textbox">
</td>
</tr>
<tr>
<td align="left" class="content-sm">
Password:</td>
</tr>
<tr>
<td align="left" class="input">
<input type="text" name="txtPWD" size="25" maxlength="8" class="textbox">
</td>
</tr>
<tr>
<td align="left" class="text_normal" valign="top">
<br />
<input type="submit" style="width:80px" name="Signin" value="Sign me in!" class="button">
<input type="reset" name="Reset" value="Reset" class="button">
</td>
</tr>
</form>
</table>
</body>
</html>
*******************đoạn code của trang logincheck.asp*******************
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Page 1</title>
</head>
<body>
<%dim strConn
strConn="Provider=SQLOLEDB.1;Persist Security Info=False;UID=sa;PWD=;Initial Catalog=QLCH ;Server=192.168.0.172"%>
<%
session.codepage=65001
strsql="select * from nhanvien where username='"& request.form("txtUser")&"'"
dim conn,rst
set conn=createobject("ADODB.connection")
set rst=createobject("ADODB.recordset")
conn.open strconn
rst.open strsql,conn
if not rst.EOF then
if rst("password")=request.form("txtPWD") then
response.redirect("adduser.htm")
else
response.redirect("login.asp")
end if
else
response.redirect("login.asp")
end if
set conn=nothing
set rst=nothing
%>
<table>
<tr><td> <%=rst("hoten")%></td></tr>
<tr><td> <%=rst("password")%></td></tr>
</table>
</body>
</html>
mình nghĩ nó sai ở chổ này : if rst("password")=request.form("txtPWD")
cái đoạn rst("password") không lấy được dữ liệu từ CSDL SQL nên khi so sánh với request.form("txtPWD") chắc chắn không trùng nhau. Các bạn có kinh nghiệm làm web vui lòng hướng dẫn mình khắc phục lỗi này. Mình xin cám ơn.
Bài liên quan
^^
vui tính quá.
thay việc kiểm tra 2 lần thì sử dụng SQL mà kiểm tra luôn, nhớ check lỗi SQL và trim dữ liệu đầu vào.
nhìn kiểu này chắc là dùng frame.
một điều nữa là bạn checklogin xong nhưng không gán session thì lấy đâu ra session mà làm việc. ^__^
Viết code quá loằng ngoằng.
response.redirect("adduser.htm")
else
response.redirect("myaccount.asp")
elseif session("suserid")=-1 then
msg="Wrong Password"
elseif session("suserid")=-2 then
msg="Invalid Username"
else
msg="Please enter your Username and Password."
end if
Đây là code trang login.asp
ĐÂY LÀ CODE TRANG KIEMTRALOGIN.ASP
login vô thi ok ,nhưng khi quay về trang login.asp là bi lỗi sau
Technical Information (for support personnel)
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "lan "]'
/congtac/login.asp, line 4
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Maxthon)
Page:
GET /congtac/login.asp
Time:
Thursday, February 26, 2009, 5:00:36 PM
More information:
Microsoft Support
không biết cái giá trị trả về cho session la kiểu nào mà thang biên dịch không so sanh duoc.
Anh em giúp mình với