...

View Full Version : Need some help with some ASP code I am using...



Clarkey Boy
04-15-2006, 07:09 PM
Hi,

I have only been learning ASP for several days now and am hoping to become a professional web designer.

I used the following code for my page - it does not come up with any errors and I used basically the same code for another page (which does work), but this page does not work as it will not submit comments from the form into the database. I would be very grateful for any help anyone could give me.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Comments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
Dim adoCon
Dim rscomments
Dim SQL
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Mode=admodesharedenynone
adoCon.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\websites/clarkeyboy/datasource/comments.mdb")
Set rscomments = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT comments FROM comments"
rscomments.CursorType = 2
rscomments.LockType = 3
rscomments.Open SQL, adoCon
%>
<form>
<strong>
Comments: (Place your comments here and press enter)
</strong>
<input type="text" rows="20" cols="150" name="comment">
</form>
<table align="center" border="3" width="100%">
<tr>
<td width="10%">
<b>
<center>
Comment Number
</center>
</b>
</td>
<td width="90%">
<b>
<center>
Comments
</center>
</b>
</td>
</tr>
<%
Dim x
x = 0
Do While not rscomments.EOF
%>
<tr>
<td width="50%">
<%
x = x + 1
Response.Write(x)
%>
</td>
<td width="50%">
<%
Response.Write (rscomments("comments"))
%>
</td>
</tr>
<%
rscomments.MoveNext
Loop
%>
</table>
<%
Dim strcomment
strcomment = Request.Form("comment")
Dim strNothing
strNothing = ""
If strcomment = strNothing Then
Response.Write("Please submit a comment")
Else
rscomments.addnew
rscomments("comments") = strComment
rscomments.update
Response.Redirect"comments.asp"
Response.Write("Thank you for submitting a comment")
End If
rscomments.Close
%>
</body>
</html>



Displaying the information from the database works fine - so the connection is definitely there - but I can't get it to create new records.

I have a database called comments, a table called comments and the column being taken from the table is also called comments - not necessarily a very good combination to call them all comments but its easy to handle at this stage.

Clarkey Boy
04-15-2006, 07:28 PM
ok... Solved it - never put the method in for the form as I didn't know quite how important it was. What EXACTLY does the "post" method actually do? And how do you use the "get" method?

degsy
04-18-2006, 03:51 PM
Post submits data.
You retrieve it using Request.Form("var")

Get grabs data using the querystring
http://www.domain.com/page.asp?id=1&user=joe

id = Request.QueryString("id")
user = Request.QueryString("user")

http://www.w3schools.com/asp/asp_ref_request.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum