|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem with inserting data to ms access databse
Dunno why. I have 3 files
users.mdb which is the databse with the information form.htm which is the FORM for the users to fill in the information and ofcourse the asp file which's called add_to_database.asp I tried SO many codes from SO many different users and none of them work. However - I learnt it few years ago and this code I use now DOES make sense but still not working to me!!! When I fill the information in the form and press "Submit" it simply goes to the ASP file and shows me the CODE of it, instead of doing the action it's meant to do ( Adding the information from the form file to the database ) damn....... can't figure it out. Here's the form Code : <html> <head> <title>Form to Database</title> </head> <body> <!-- comment - start the HTML form and use a HTML table for formatting--> <form name="form1" action="add_to_database.asp" method="post"> <div align="center"> <table width="80%" border="0"> <tr> <td>Name :</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Email :</td> <td> <input type="text" name="email"></td> </tr> <tr> <td>Comments :</td> <td><textarea name="comments"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" value="submit details" name="submit"></td> </tr> </table> </div> </form> <!-- end the HTML form--> </body> </html> Here's the ASP Code : <html> <head> <title>Form to database</title> </head> <body> <% Dim name, email, comments Dim sConnString, connection, sSQL name = Request.Form("name") email = Request.Form("email") comments =Request.Form("comments") sSQL = "INSERT into users_tbl (name, email, comments) values ('" & _ name & "', '" & email & "', '" & comments & "')" sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("Users.mdb") Set connection = Server.CreateObject("ADODB.Connection") connection.Open(sConnString) connection.execute(sSQL) response.write "The form information was inserted successfully." connection.Close Set connection = Nothing %> </body> </html> And here's the result I get when I fill the information on form page and clicks "submit" : <% Dim name, email, comments Dim sConnString, connection, sSQL name = Request.Form("name") email = Request.Form("email") comments =Request.Form("comments") sSQL = "INSERT into users_tbl (name, email, comments) values ('" & _ name & "', '" & email & "', '" & comments & "')" sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("Users.mdb") Set connection = Server.CreateObject("ADODB.Connection") connection.Open(sConnString) connection.execute(sSQL) response.write "The form information was inserted successfully." connection.Close Set connection = Nothing %> I get the code... can some1 help ? is the code wrong ? my settings ? Wtf o.0 |
|
#2
|
||||
|
||||
|
If that code is in a file named form.htm, the web server will not try to process the vbscript code, it will just print it out. Try changing the filename to form.asp and see if that works.
__________________
Experience is the thing you have left when everything else is gone. |
|
#3
|
|||
|
|||
|
You didn't understand..
Only the FORM file is under .html the ASP file is of course .asp but anyway I changed the form file to .asp too and no result same error... btw I'm running it on my pc, doesn't matter ya? |
|
#4
|
||||
|
||||
|
How are you trying to view the page, just directing your browser to the file? That won't work, because ASP has to be interpreted by a web server. If you have a web server running on your local work station, you must address it as
Code:
localhost/form.htm |
|
#5
|
|||
|
|||
|
how do I check if i have a web server running ?
and how do I turn it on anyway, how to access the file when its lcoated @ C:\Documents and Settings\Shlomi\My Documents\New Folder\Form.htm |
|
#6
|
|||
|
|||
|
Ok, so I set up a localhost and ran my files through that.
Now when I click submit, I get an error page not found ... here is the code # Error Type: Microsoft JET Database Engine (0x80004005) Operation must use an updateable query. /add_to_database.asp, line 28 # Browser Type: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 # Page: POST 70 bytes to /add_to_database.asp # POST Data: name=sss&email=xzamer%40gmail.com&comments=aaaaa&submit=submit+details line 28 is the command Execute and it refers in the error to this line : sSQL = "INSERT into users_tbl (name, email, comments) values ('" & _ name & "', '" & email & "', '" & comments & "')" now what's wrong with that? |
|
#7
|
||||
|
||||
|
I'm not sure, several of the things you said sound like they aren't related. Let's take them one at a time.
For security reasons, all web servers deliberately are restricted from serving files located anywhere but within the "document root" directory that is specified in the configuration file, which is usually named httpd.config. So you can't have either your form.html or your add_to_database.asp file located in your My Documents folder (unless, of course, you designate that as your document root, which you would normally not want to do). That's probably why you are getting a "file not found" error. However, the "updateable query" error certainly sounds like it is finding and interpreting your asp file. That particular error, though, is usually seen when trying to do an Update query with joined tables. I don't quite know what to make of it if it refers to an Insert query. I also don't see anything wrong with the SQL there. One tip, although I doubt that it's causing your problem, is to avoid using "reserved words" as field names or variable names, as you are doing with the variable and field name "Name". You can avoid triggering the error by enclosing Name in brackets: [Name], but you really should rename that field and then the variable. Otherwise, Access gets confused. In a situation like this, what I would do next is temporarily replace your Insert query with a very simple Select query, just "Select * From users_tbl", to see whether you can connect and read data from the database. If you can, something is wrong with your Insert query, like a misspelled fieldname or missing data, or something like that. If you can't even get a Select query to run, something is wrong with your connection string or something. |
|
#8
|
|||
|
|||
|
I am really not that good with SQL as I used to be , can u give me the full command u refer to?
Also, as u can notice in my last poste, I did setup a localhost and ran the files through localhost ( intepub/wwwroot ) so there's a problem with my code, I think.. |
|
#9
|
|||
|
|||
|
Quote:
any idea some1? |
|
#10
|
|||
|
|||
|
Quote:
.... please help :< |
|
#11
|
||||
|
||||
|
Please don't "bump" within 24 hours of a post.
I did give you the full SQL statement. Read my last paragraph. It's in quotes. |
|
#12
|
|||
|
|||
|
Quote:
SLECECT and then ? just typing select * from and the name of the table ? nothing else? |
|
#13
|
||||
|
||||
|
Code:
SELECT * FROM yourtablename |
|
#14
|
|||
|
|||
|
I understood, replacing the whole query with the "SELECT * FROM MyTableName " query, however, after selecting, I need to give him another command to do with what he selected, so I can see a result, or not ? just keep it as select to see if it can access the DB ?
Assuming I type only select, and it does no error. does it mean that i CAN connect my DB and smth is probably wrong with code ? |
|
#15
|
||||
|
||||
|
That's essentially correct. You could carry it further and list the first record or something, but what I was suggesting is just see if you can execute a simple Select query, as a way of narrowing where the problem is.
|
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > Problem with inserting data to ms access databse |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|