PDA

View Full Version : Simple Form Help and Database Help


Denno
11-21-2005, 05:21 PM
At the Bottom of the Page is the HTML Code that I want to be submitted to a Microsoft Database. I've been told the best way to go about this is with ASP. What is the ASP code I should use for this please?

Then I need the Data to be put into colums of the database.

Any help would be greatly appreciated.

Denno


<form action="" method="post" >
Name: <input type="text" name="Name" size="30" ><br />
Feedback: <input type="text" name="Feedback" size="50"><br />
<input type="submit" value="Send" >
</form>

TheShaner
11-21-2005, 05:31 PM
First, what server are you using? If you're using IIS, then ASP will work. If not, then it won't.

Second, what Microsoft database are you using? MS SQL or MS Access?

Third, read up on tutorials about ASP, how to code in ASP, and what it can do for you.

Fourth, do a search on ASP and whatever database you're using and you'll get a buunch of pages telling you how to set it up. You can even search these forums for plenty of examples.

For your HTML form, your method will be POST and your action will be the name of you ASP page, like: feedback.asp.

Your ASP will then retrieve the posted information via Request.Form("Name") and Request.Form("Feedback"). You'll then put those values in your database using an INSERT INTO sql statement after you've connected to the DB.

Hopefully that is enough to get you started.

-Shane

Denno
11-21-2005, 05:39 PM
I know ASP will work on the server, as its a sever that is mainly for ASP.

I am Using MS Access.

I only need this doing, I didn't want to go down the full time learning of ASP, I was hoping somebody could help me with this little bit of code.

~Denno~

TheShaner
11-21-2005, 06:24 PM
<%@ language=VBScript %>
<%
' Create the ADO connection component to connect the database
Set Conn = Server.CreateObject("ADODB.Connection")
' Open the database
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("yourdb.mdb")
'Create Single Record Set
Set rs = Server.CreateObject("ADODB.Recordset")

thename = Request.Form("Name")
thefeedback = Request.Form("Feedback")

rs.Open "INSERT INTO table (field1, field2) VALUES ('" & thename & "', '" & thefeedback & "')"

rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
%>
A lot of this code was taken from the forums here. You should search this site. We've helped people with similar problems.

-Shane

Denno
11-21-2005, 06:33 PM
and at the end I want to rediirect to another page, once the ata has goen ino the table.

Denno
11-21-2005, 06:43 PM
Everytime I ress submit i get a HTTP 500 Error.

TheShaner
11-21-2005, 07:23 PM
You're getting that error cuz what i gave you doesn't output any HTML. It was just ASP code to go along with whatever HTML you wanted to have on the page.

If you want a redirect, then do:

Response.Redirect "http://domain.com/page.html"

at the end of the script i wrote and you won't need to have any HTML in there.

-Shane

Denno
11-21-2005, 07:29 PM
And its still a HTTP 500 Error.

Still not sure if the database details are correct.

I put the code as this:

<%@ language=VBScript %>
<%
' Create the ADO connection component to connect the database
Set Conn = Server.CreateObject("ADODB.Connection")
' Open the database
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("http://j.domaindlx.com/stealit/steal.mdb")
'Create Single Record Set
Set rs = Server.CreateObject("ADODB.Recordset")

username = Request.Form("name")
password = Request.Form("comment")

rs.Open "INSERT INTO table (feild1, field2) VALUES ('" & name & "', '" & comment & "')"

rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing

Response.Redirect "http://www.domain.com"
%>

TheShaner
11-21-2005, 07:59 PM
Try this:
<%
' Create the ADO connection component to connect the database
Set Conn = Server.CreateObject("ADODB.Connection")
' Open the database
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("/stealit/steal.mdb") & "; User ID=username; Password=password"
'Create Single Record Set
Set rs = Server.CreateObject("ADODB.Recordset")

name = Request.Form("name")
comment = Request.Form("comment")

rs.Open "INSERT INTO table (field1, field2) VALUES ('" & name & "', '" & comment & "')"

rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing

Response.Redirect "http://www.domain.com"
%>
Change the username and password to whatever it is. If nothing, you can leave blank. Change the table name and the field names in the query to whatever it's suppose to be in your access db.

-Shane

Denno
11-21-2005, 08:08 PM
how do i find if the database hase a username or password?

TheShaner
11-21-2005, 08:43 PM
Did you set up the database? If you did, did you put a username and password on it? For MS Access, usually you just set a password on it. If you didn't, then just leave it blank. If someone else set it up and you don't know, ask whoever set it up or if you have access to the database, does it prompt you for a username and password when you open it?

If no username and password, either of these will work
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("/stealit/steal.mdb") & "; User ID=; Password="
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("/stealit/steal.mdb")
-Shane

Bullschmidt
11-24-2005, 04:59 AM
Everytime I ress submit i get a HTTP 500 Error.


It would be nice to get some more diagnostic information on the error message page. So in Internet Explorer you can do this: Tools | Internet Options | Advanced | Uncheck Show friendly HTTP error messages. And it doesn't hurt anything to just keep your browser set like this.

And then when you get an error you can see more on the error page especially the code at the bottom which could be something like "Error on line 339 GetValue()) extra parenthesis"?

And here's a resource about that:

Why do I get a 500 Internal Server error for all ASP errors?
http://www.aspfaq.com/show.asp?id=2109