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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem inserting a record into table

Status
Not open for further replies.

ola123

Technical User
Sep 16, 2005
52
JM
Hi guys,

I here teaching my self some asp using w3schools.com. I typed all the code on the page ( that should allow me to enter a record into a table, but for the love of me the thing not working.

if it's possible could someone tell me where i went wrong
Code:
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\[URL unfurl="true"]wwwroot\database.mdb"[/URL]

sql="INSERT INTO table (name,id,"
sql=sql & "age)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("name") & "',"
sql=sql & "'" & Request.Form("id") & "',"
sql=sql & "'" & Request.Form("age") & "')" 

on error resume next
conn.Execute sql, recaffected

if err<>1 then
  Response.Write("No update permissions!")
else 
  Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>

</body>
</html>

Thanks much in advance
 
It will be a lot easier to debug once you get to see the error message.

To see the error message:
1. Temporarily remove or comment out the line [tt]on error resume next[/tt]

2. Un-select "show friendly HTTP error messages" in your browser if you are using IE it is under menu Tools -> Internet Options -> Advanced tab
 


I am a VERY elementary ASP programmer but I would recommend the practice of doing a dim statement for variables:

Code:
<% Option Explicit %> 
...
<% dim conn, sql, recaffected %>
...

That helps me out sometimes in figuring out what I screwed up.

 
Are the name, id, and age fields all text fields in the database? If any of them are not, they shouldn't be surrounded by single-quotes.

Also, do a search for SQL Injection.
 
>if err<>1 then
[tt]if err.number<>[red]0[/red] then[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top