ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 24th, 2009, 07:47 PM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
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>&nbsp;</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

Reply With Quote
  #2  
Old June 24th, 2009, 08:17 PM
don94403's Avatar
don94403 don94403 is offline
Contributing User
Click here for more information.
 
Join Date: Jan 2007
Location: Northern California
Posts: 2,886 don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 1 h 18 m 41 sec
Reputation Power: 562
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.

Reply With Quote
  #3  
Old June 24th, 2009, 08:23 PM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
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?

Reply With Quote
  #4  
Old June 24th, 2009, 08:54 PM
don94403's Avatar
don94403 don94403 is offline
Contributing User
Click here for more information.
 
Join Date: Jan 2007
Location: Northern California
Posts: 2,886 don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 1 h 18 m 41 sec
Reputation Power: 562
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
or whatever it's named.

Reply With Quote
  #5  
Old June 24th, 2009, 09:19 PM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
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

Reply With Quote
  #6  
Old June 24th, 2009, 10:24 PM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
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?

Reply With Quote
  #7  
Old June 24th, 2009, 11:37 PM
don94403's Avatar
don94403 don94403 is offline
Contributing User
Click here for more information.
 
Join Date: Jan 2007
Location: Northern California
Posts: 2,886 don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 1 h 18 m 41 sec
Reputation Power: 562
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.

Reply With Quote
  #8  
Old June 25th, 2009, 05:43 AM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
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..

Reply With Quote
  #9  
Old June 25th, 2009, 09:27 AM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
Quote:
Originally Posted by xzamer
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..


any idea some1?

Reply With Quote
  #10  
Old June 25th, 2009, 07:31 PM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
Quote:
Originally Posted by xzamer
any idea some1?


.... please help :<

Reply With Quote
  #11  
Old June 25th, 2009, 08:42 PM
don94403's Avatar
don94403 don94403 is offline
Contributing User
Click here for more information.
 
Join Date: Jan 2007
Location: Northern California
Posts: 2,886 don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 1 h 18 m 41 sec
Reputation Power: 562
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.

Reply With Quote
  #12  
Old June 26th, 2009, 11:17 AM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
Quote:
Originally Posted by don94403
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.



SLECECT and then ? just typing select * from and the name of the table ? nothing else?

Reply With Quote
  #13  
Old June 26th, 2009, 03:29 PM
don94403's Avatar
don94403 don94403 is offline
Contributing User
Click here for more information.
 
Join Date: Jan 2007
Location: Northern California
Posts: 2,886 don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 1 h 18 m 41 sec
Reputation Power: 562
Code:
SELECT * FROM yourtablename
As I said, a simple Select SQL query. Indeed, the simplest possible. It just instructs the database engine to send all the fields from all the rows in that table. All you want to do is determine whether you are connecting to your database. Now, when you ask about "typing" something, I don't know what you have in mind. Of course you have to send that query to the database, but since you already had all that code in your previous post, I assumed that you understood that you just need to substitute the SQL.

Reply With Quote
  #14  
Old June 26th, 2009, 09:07 PM
xzamer xzamer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 xzamer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m
Reputation Power: 0
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 ?

Reply With Quote
  #15  
Old June 26th, 2009, 10:35 PM
don94403's Avatar
don94403 don94403 is offline
Contributing User
Click here for more information.
 
Join Date: Jan 2007
Location: Northern California
Posts: 2,886 don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level)don94403 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 1 h 18 m 41 sec
Reputation Power: 562
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > Problem with inserting data to ms access databse


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek