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.
huonghx viết 11:43 ngày 10/10/2018
trang login thì post đến trang test, nhưng lại đưa code trang logincheck
^^
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.


if rst("password")=request.form("txtPWD") then
response.redirect("adduser.htm")
else
session gán chỗ nào ??

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
muôn đời quay về login
duongdangquoc viết 11:38 ngày 10/10/2018
Login với asp.net gì mà cực wa' vậy? Vậy là đò án to cỡ nào trời.
ngoc_viet08 viết 11:37 ngày 10/10/2018
ừ , khó nhỉ . login với php dễ quá trời luôn . có phải ko các bác . sai cứ chửi , em rút kinh nghiệm
viettech viết 11:38 ngày 10/10/2018
Tui xin trình bày với các bác 1 trường hợp cũng xãy ra trên login asp

Đây là code trang login.asp
Code:
<%
if session("sid")>0 then
Response.Redirect("nhapquatrinh.asp")
elseif session("sid")=-1 then
 msg="vui long kiem tra lai ten dang nhap va mat khau"
end if
%>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<SCRIPT language=javaScript>
function checkInput()
{if(document.formLogin.T1.value=="")
 {alert("vui long nhap ten dang nhap");
document.formLogin.T1.focus();
return false;
 }
 if (document.formLogin.T2.value=="")
 {alert("vui long nhap mat khau");
 document.formLogin.T2.focus();
 return false;
 }
 return true;
}
</script>
</HEAD>
<BODY>
<!--#include file=config.inc-->



<form name="formLogin" method="POST" action="kiemtralogin.asp" onsubmit="return checkInput();">
	<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
	<p><font face="Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<font size="4" color="#3399FF">CH***431;***416;NG TRÌNH THÔNG TIN NHÂN S***7920; 
	BHXH T***7880;NH BR-VT</font></font></p>
	<p><font color="#3399FF" face="Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
	Tên ***273;***259;ng nh***7853;p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="T1" size="30"></font></p>
	<p><font color="#3399FF" face="Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
	M***7853;t kh***7849;u&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T2" size="30"></font></p>
	<p><font color="#3399FF" face="Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="submit" value="***272;***259;ng nh***7853;p" name="B1" tabindex="0">&nbsp;&nbsp;
	<input type="reset" value="Reset" name="B2" tabindex="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</font></p>
</form>





 
<P>&nbsp;</P>

</BODY>
</HTML>



ĐÂY LÀ CODE TRANG KIEMTRALOGIN.ASP
Code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</HEAD>
<BODY>
<!--#include file=config.inc-->
<%dim sqlkt,rs,bten,bpass
session.CodePage=65001
bten=Request.Form("T1")
bpass=Request.Form("T2") 
set rs=Server.CreateObject("ADODB.recordset")
sqlkt="select * from TBHOSO where id='" & bten & "'and pass='" & bpass & "'"
rs.Open sqlkt,cn
if not rs.EOF  then
   'if bpass=rs("pass") then
'khoi tao session
'session("sid")=0
session("sid")=rs.("id")
session("suname")=bten
session("sfullname")=rs("TEN")
session("namsinh")=rs("NAMSINH")
Response.Redirect("nhapquatrinh.asp")
'Response.Write " <h4> LOGIN SUCCESSFUL </h4>"
else
session("sid")=-1
Response.Redirect("login.asp")
'response.Write "<h4> USER NAME & PASSWORD NOT MATCHING </h4>"
end if
set rs=nothing
close cn
%>

<P>&nbsp;</P>

</BODY>
</HTML>

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
Bài liên quan
0