473,769 Members | 6,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

whats wrong with my insert statement

23 New Member
im trying to add form data in to my local sql 2005 database but having a lot of trouble. I have searched the web but im coming across misleading information time and time again.

below is my code

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Submit Document</title>
  6. </head>
  7. <body>
  8. <%
  9. Set conn = Server.CreateObject("ADODB.Connection")
  10. objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
  11. Server.MapPath ("laptop\omar.mdb") & ";"
  12. objConn.Open
  13.  
  14. sql="INSERT INTO webform (txtAmount,txtPurpose,"
  15. sql=sql & "txtResidentialStatus,txtTitle,txtFirstName,txtSurname,txtContactNumber,txtEveningNumber,txtEmailAddress)"
  16. sql=sql & " VALUES "
  17. sql=sql & "('" & Request.Form("txtAmount") & "',"
  18. sql=sql & "'" & Request.Form("txtPurpose") & "',"
  19. sql=sql & "'" & Request.Form("txtResidentialStatus") & "',"
  20. sql=sql & "'" & Request.Form("txtTitle") & "',"
  21. sql=sql & "'" & Request.Form("txtFirstName") & "',"
  22. sql=sql & "'" & Request.Form("txtSurname") & "',"
  23. sql=sql & "'" & Request.Form("txtContactNumber") & "')"
  24. sql=sql & "'" & Request.Form("txtEveningNumber") & "')"
  25. sql=sql & "'" & Request.Form("txtEmailAddress") & "')"
  26.  
  27. on error resume next
  28. conn.Execute sql,recaffected
  29. if err<>0 then
  30.   Response.Write("No update permissions!")
  31. else 
  32.   Response.Write("<h3>" & recaffected & " record added</h3>")
  33. end if
  34. conn.close
  35. %>
  36.  
  37.  
  38. </body>
  39. </html>
  40.  
can some one help please?
Jan 3 '09 #1
7 1574
ck9663
2,878 Recognized Expert Specialist
1. What's the error that you're getting?

2. Display the value of the your sql variable and paste it to your query analyzer. See what error will show up.

-- CK
Jan 3 '09 #2
studentofknowledge
23 New Member
this is what i'm getting on the next page

<% Set conn = Server.CreateOb ject("ADODB.Con nection") ConnectionStrin g = "Provider = SQLNCLI;" & _ "Data Source = LAPTOP\\SQLEXPR ESS;" & _ "Initial Catalog = zion.mdb;" & _ "User ID = ej2_sleeper;" & _ "Password = jennifer1;" Server.MapPath ("laptop\omar.m db") & ";" conn.Open txtAmount = Trim(Request.Fo rm("txtAmount") ) txtPurpose = Trim(Request.Fo rm("txtPurpose" )) txtResidentialS tatus = Trim(Request.Fo rm("txtResident ialStatus")) txtTitle = Trim(Request.Fo rm("txtTitle") ) txtFirstName = Trim(Request.Fo rm("txtFirstNam e")) txtSurname = Trim(Request.Fo rm("txtSurname" )) txtContactNumbe r = Trim(Request.Fo rm("txtContactN umber")) txtEveningNumbe r = Trim(Request.Fo rm("txtEveningN umber")) txtEmailAddress = Trim(Request.Fo rm("txtEmailAdd ress")) sql="INSERT INTO dbo.tbl_custome r (txtAmount,txtP urpose,txtResid entialStatus,tx tTitle,txtFirst Name,txtSurname ,txtContactNumb er,txtEveningNu mber,txtEmaildd ress)" sql=sql & " VALUES ('"&txtAmount&" ','"&txtPurpose &"', '"&txtResidenti alStatus& "','"&txtTitle& "','"&txtFirstN ame&"','"&txtSu rname&"','"&txt ContactNumber&" ', '"&txtEveningNu mber&"', '"&txtEailAddre ss&"')" conn.execute(sq l) 'if err<>0 then ' Response.Write err.Description 'else ' Response.Write( "
record added
") 'end if conn.close %>

not sure how to respond to your 2nd point as I dont understand..
Feb 22 '09 #3
ck9663
2,878 Recognized Expert Specialist
Do something like:

Response.Write( sql)

It will display the sql text. Copy the entire text and open a query window. Paste it on the query window and execute it. It'll give you detailed information on the error.

-- CK
Feb 23 '09 #4
studentofknowledge
23 New Member
hi CK thanks for your reply

i have modified my code according to your suggestion - but I still get all this info displayed on the page? below is updated code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Submit Document</title>
</head>
<body>
<%
Set conn = Server.CreateOb ject("ADODB.Con nection")
ConnectionStrin g = "Provider = SQLNCLI;" & _
"Data Source = LAPTOP\\SQLEXPR ESS;" & _
"Initial Catalog = zion.mdb;" & _
"User ID = ej2_sleeper;" & _
"Password = jennifer1;"
Server.MapPath ("laptop\omar.m db") & ";"

conn.Open
txtAmount = Trim(Request.Fo rm("txtAmount") )
txtPurpose = Trim(Request.Fo rm("txtPurpose" ))
txtResidentialS tatus = Trim(Request.Fo rm("txtResident ialStatus"))
txtTitle = Trim(Request.Fo rm("txtTitle") )
txtFirstName = Trim(Request.Fo rm("txtFirstNam e"))
txtSurname = Trim(Request.Fo rm("txtSurname" ))
txtContactNumbe r = Trim(Request.Fo rm("txtContactN umber"))
txtEveningNumbe r = Trim(Request.Fo rm("txtEveningN umber"))
txtEmailAddress = Trim(Request.Fo rm("txtEmailAdd ress"))

sql="INSERT INTO dbo.tbl_custome r (txtAmount,txtP urpose,txtResid entialStatus,tx tTitle,txtFirst Name,txtSurname ,txtContactNumb er,txtEveningNu mber,txtEmaildd ress)"
sql=sql & " VALUES ('"&txtAmount&" ','"&txtPurpose &"', '"&txtResidenti alStatus& "','"&txtTitle& "','"&txtFirstN ame&"','"&txtSu rname&"','"&txt ContactNumber&" ', '"&txtEveningNu mber&"', '"&txtEailAddre ss&"')"

conn.execute(sq l)
if err<>0 then
Response.Write( sql)
else
Response.Write( "<h3> record added</h3>")
end if
conn.close
%>


</body>
</html>
Feb 23 '09 #5
ck9663
2,878 Recognized Expert Specialist
Check your connection string.

Here are more about it.


-- CK
Feb 23 '09 #6
studentofknowledge
23 New Member
thanks CK - maybe my connection string is incorrect after all. I've checked the site but not sure which string to use;

Providers to use when connecting to SQL Server 2005
» .NET Framework Data Provider for SQL Server (SqlConnection)
» SQL Native Client 9.0 OLE DB provider
» .NET Framework Data Provider for OLE DB (OleDbConnectio n)
» SQL Server Native Client 10.0 OLE DB Provider
» SQL Native Client 9.0 ODBC Driver
» SQL Server Native Client 10.0 ODBC Driver
» .NET Framework Data Provider for ODBC (OdbcConnection )
» SQLXML 4.0 OLEDB Provider
» Context Connection

I'm using SQL 2005 express with classic ASP on my vista laptop if that helps. Just trying to populate a table in my local SQL database via a local html webform.

please advise and many thanks in advance :)
Feb 23 '09 #7
ck9663
2,878 Recognized Expert Specialist
SQL Server family can be access by using the same connection string. Try one of these. You're doing it right using classic ASP.

Also, I'm not responding on your other post. Your insert on your other post will not work until you make your connection work.Try to make your connection work first, then do some simple SELECT. Then proceed to INSERT.

-- CK
Feb 23 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3842
by: cricketunes | last post by:
Hi folks, this one's had me stumped! $conn=ora_logon("cricketunes@pickles","j8j3kf"); if ($conn != TRUE) die("Unable to connect to oracle, exiting...\n"); $cursor = ora_open($conn); if ($cursor != TRUE) die("Unable to open a cursor, exiting...\n");
5
2094
by: Mike M | last post by:
Hi all, I ahve the following SQL string but when i try to response.Write it there is a error where the ',' should be between "city" and "County" SQL = "INSERT * INTO customers (Company_Name, Category, Contact_Name, Contact_Title, Address_1, Address_2, City, County, Post_Code, Phone_1, Phone_2, Fax, Web_URL, email_Address, Delivery, Notes)" SQL = SQL & " VALUES('" & Request.Form("Company_Name") & "','" &
4
5616
by: Simom Thorpe | last post by:
Hi, I'm trying to insert a line into a MS access DB using ASP on IIS 5. This is the line: con.execute "INSERT INTO newProds(title,desc,catcode) VALUES ('Champagne Muff Scarf','','AC304B')" But it throws up this error:
2
7811
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a lot of repeats and the concatenation field date always comes back as January 2003 instead of the month and date its supposed to --Fiscal Year
3
2395
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."', '".$_POST."')"); ?> <script language="JavaScript"> <!--
8
1838
by: Brian Basquille | last post by:
Hello all, Bit of a change of pace now. As opposed to the typical questions regarding my Air Hockey game, am also working on a Photo Album which uses an Access Database to store information about photos. This information is held inside the database (photoDB.mdb) in a table called 'photos' - information being recorded in there are photo information (photoID, location, phDate, category, caption). I have inputted my own photos (not via...
3
6737
by: brianbasquille | last post by:
Hello all, Strange little problem here... am just trying to insert some basic information into an Access Database using OleDB. I'm getting a "Syntax error in Insert Into statement" when it tries to execute the SQL. The strange thing is if i take the exact SQL being executed from the debugger and insert and execute it using the MS Access query engine, it works fine!
1
1146
by: ramyap2 | last post by:
<html> <body> <%@ page import="java.sql.*" %> <% Connection con=null; Statement st=null; ResultSet rs= null;
5
1721
by: hiqu | last post by:
This issue is driving me nuts and not able to figure out whats wrong. I've this code in my firefox extension. Firefox always hangs and reports the script is busy. if I introduce a break statement in the for(;;) loop below, then no issue. Any help would be appreciated! function getStuff()
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.