Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forum problems

Status
Not open for further replies.

cheekynorton

Technical User
Jan 21, 2002
12
0
0
GB
Hi I could use some help with my forum.
Firstly i have default.asp which is the login page:-

<html>
<head>
<title>My Forum</title>
</head>

<body>

<form name=&quot;login&quot; action=&quot;login_process.asp&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;login&quot;>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;250&quot;>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot; bgcolor=&quot;orange&quot;><b>User Login</b></td>
</tr>
<tr>
<td><b>Username</b></td><td align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;username&quot; size=&quot;20&quot;></td>
</tr>

<tr>
<td><b>Password</b></td><td align=&quot;right&quot;>
<input type=&quot;password&quot; name=&quot;password&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td colspan=&quot;2&quot; align=&quot;right&quot;><input type=&quot;submit&quot; value=&quot;Login&quot;></td>
</tr>

</table>
</form>

<form name=&quot;login&quot; action=&quot;login_process.asp&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;register&quot;>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;250&quot;>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot; bgcolor=&quot;orange&quot;><b>No username? Register here.</b></td>
</tr>
<tr>
<td><b>Username</b></td><td align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;username&quot; size=&quot;20&quot;></td>
</tr>

<tr>
<td><b>Password</b></td><td align=&quot;right&quot;>
<input type=&quot;password&quot; name=&quot;password&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td><b>Confirm</b></td><td align=&quot;right&quot;>
<input type=&quot;password&quot; name=&quot;confirm&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td colspan=&quot;2&quot; align=&quot;right&quot;><input type=&quot;submit&quot; value=&quot;Register&quot;></td>
</tr>

</table>
</form>

</body>
</html>

---------------------------------------
Secondly the login_process.asp. Code to execute the form, registering a new user to the database or login, then taking the user to the main forum.

<%@LANGUAGE = &quot;VBSCRIPT&quot;%>

<%
strErr = &quot;&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; &_
Server.MapPath(&quot;\forum\forum.mdb&quot;)

if request(&quot;action&quot;) = &quot;login&quot; then

if request(&quot;username&quot;) = &quot;&quot; then
strErr = strErr & &quot;Username is a required field&quot; & vbCrLf
end if
if request(&quot;password&quot;) = &quot;&quot; then
strErr = strErr & &quot;Password is a required field&quot; & vbCrLf
end if
if strErr = &quot;&quot; then

SQL = &quot;select username, password from users where username = '&quot; & request(&quot;username&quot;) & &quot;'&quot;
set RSuser = Conn.execute (SQL)

if not RSuser.BOF and not RSuser.EOF then

if RSuser(&quot;password&quot;) = request(&quot;password&quot;) then
Response.Redirect(&quot;list.asp&quot;)
else
strErr = strErr & &quot;Invalid password&quot; & vbCrLf
end if

else
strErr = strErr & &quot;User not registered&quot; & vbCrLf
end if

end if

elseif request(&quot;action&quot;) = &quot;register&quot; then

if request(&quot;username&quot;) = &quot;&quot; then
strErr = strErr & &quot;Username is a required field&quot; & vbCrLf
end if
if request(&quot;password&quot;) = &quot;&quot; then
strErr = strErr & &quot;Password is a required field&quot; & vbCrLf
end if
if strErr = &quot;&quot; then
if request(&quot;password&quot;) <> request(&quot;confirm&quot;) then
strErr = strErr & &quot;Password must match the confirmation&quot; & vbCrLf
else

SQL = &quot;select username from users where username = '&quot; & request(&quot;username&quot;) & &quot;'&quot;
set RSuser = Conn.execute (SQL)

if not RSuser.BOF and not RSuser.EOF then
strErr = strErr & &quot;This username already exists&quot; & vbCrLf
else
SQL = &quot;insert into users (username, password, date_created, date_modified) VALUES ('&quot; & request(&quot;username&quot;) & &quot;', '&quot; & request(&quot;password&quot;) & &quot;', '&quot; & now & &quot;', '&quot; & now & &quot;')&quot;
Conn.execute (SQL)
end if
end if
end if


else
strErr = strErr & &quot;Unrecognised Action, please resubmit&quot; & vbCrLf
end if
%>

<%
if strErr <> &quot;&quot; then
%>
<html>
<head>
<title>Error</title>
</head>
<body>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;400&quot;>
<tr>
<td><b>The following errors were detected:</b></td>
</tr>
<tr>
<td><%=strErr%></td>
</tr>
<tr>
<td>Please go <a href=&quot;login.asp&quot;>back</a> and correct them.</td>
</tr>
</table>
</body>
</html>

<%else%>
<html>
<head>
<title>Registration</title>
</head>

<body>

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;400&quot;>
<tr>
<td><b>Registration completed</b></td>
</tr>
<tr>
<td>Click <a href=&quot;list.asp&quot;>here</a> to enter the forum.</td>
</tr>
</table>
</body>
</html>
<%end if%>
<%Conn.close%>

----------------------------------

Thirdly the list.asp, which is the first page in the forum listing all the posted messages.

<%@LANGUAGE = &quot;VBSCRIPT&quot;%>

<% session(&quot;username&quot;) = request(&quot;username&quot;)

if session(&quot;username&quot;) = &quot;&quot; then
response.redirect(&quot;default.asp&quot;)
end if
%>

<%
Dim Conn, ConnString
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
ConnString = &quot;DRIVER={Microsoft Access Driver (*.mdb)};&quot; & _
&quot;DBQ=C:\inetpub\Conn.Open(ConnString)

sql = &quot;select id, title, date_created from messages where parent_id = 0 order by date_created&quot;
Set RS = Conn.Execute(sql)

%>

<html>
<head>
<title>Forum</title>
<STYLE TYPE=&quot;text/css&quot;>
font { font-family:verdana }
a { color:000000 }
a:visited { color: 000000 }
.cell { font-size:14px ; color:black }
.title { font-family:arial ; font-size:16px ; line-height: 18px ; font-weight:bold; vertical-align:top }
</STYLE>
</head>
<body bgcolor=&quot;E3EEEE&quot;>

<table border=0 width=&quot;400&quot; cellspacing=&quot;1&quot;>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot;><button onclick=&quot;location.href='post.asp'&quot;>New Topic</button></td>
</tr>
<tr>
<td bgcolor=&quot;19CBC5&quot; class=&quot;title&quot;> <b>Topic</b></td>
<td bgcolor=&quot;19CBC5&quot; align=&quot;center&quot; class=&quot;title&quot;><b>Date posted</b></td>
</tr>

<% while not RS.EOF and not RS.BOF %>
<tr>
<td bgcolor=&quot;AAE4E2&quot; class=&quot;cell&quot;> <a href=&quot;message.asp?id=<%=RS(&quot;id&quot;)%>&quot;><%=RS(&quot;title&quot;)%></a></td>
<td bgcolor=&quot;AAE4E2&quot; align=&quot;center&quot; class=&quot;cell&quot;><%=RS(&quot;date_created&quot;)%></td>
</tr>
<%RS.movenext
wend %>

<tr>
<td colspan=&quot;2&quot; bgcolor=&quot;19CBC5&quot;> </td>
</tr>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot;><button onclick=&quot;location.href='post.asp'&quot;>New Topic</button></td>
</tr>

</table>

</body>
</html>
<%Conn.close%>

----------------------------
Using the code i can happily add a new user.
The problem seems to be getting to the list.asp (main forum page).
Upon successfully registering, the user is given a link to list.asp (main forum page).
Upon clicking the link, instead of going to list.asp the user is taken back to default.asp implying that the user is 'not logged in'.
This also happens if the user logs in, instead of being redirected to list.asp he is sent back to default.
Can someone please tell me what i am doing wrong, is there anything wrong with code?
I guess its something to do with the validation code in login_process.asp but i cannot decipher the problem.
This is all pretty new to me :)
Thanks for any help!

Adrian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top