Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2004, 10:59 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax error in INSERT INTO statement

Hi,

I am currently working on chapter 16. I have created the database and the relevant asp pages. However, when i submit my name, address and telephone number in the AddOrderDetails form i get the following error message:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
/test_database/AddOrderDetails.asp, line 41


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Page:
POST 94 bytes to /test_database/AddOrderDetails.asp

POST Data:
txtStockId=&txtCustomerName=test&txtCustomerAddres s=test&txtTelNumber=23232&submit1=Send+Order

Time:
12 July 2004, 16:54:22

I have double checked the spelling of each field name and they are all correct. Any Ideas?

 
Old July 12th, 2004, 03:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,
[
That's a SQL error, so I will have to see the statement to make a suggestion. In addition, if you do a:

Response.Write(strSQL)
Response.End

before you execute it, you can see what the error may be in the SQL.

Brian
 
Old July 13th, 2004, 03:14 AM
Authorized User
 
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi stephan here is some code that i have been working on works fine for me.
hope it helps !javascript:insertsmilie(';)')
Wink ;)



<%@LANGUAGE="JAVASCRIPT"%>
<%
// getting values from previous form
var sn,fn,surn,a1,a2,a3,ext,mobile,email,dob;
sn = Request.Form("staffNumber");
fn = Request.Form("firstname");
surn = Request.Form("surname");
a1 = Request.Form("address1");
a2 = Request.Form("address2");
a3 = Request.Form("address3");
ext = Request.Form("extn");
mobile = Request.Form("mobile");
email = Request.Form("email");
dob = Request.Form("day1") +"/"+Request.Form("month1")+"/"+Request.Form("year1");

adoConnection = Server.CreateObject("ADODB.Connection");
adoConnection.Open("DSN=input");

var SQL = "INSERT INTO tblStaff (staffID,firstname,surname,DateOfBirth,address1,ad dress2,address3,extn,mobile,email)";
SQL = SQL + "VALUES("+sn+",'"+fn+"','"+surn+"','"+dob+"','"+a1 +"','"+a2+"','"+a3+"',"+ext+","+mobile+",'"+email+ "')";

adoConnection.Execute(SQL);
adoConnection.Close();
adoConnection = null;
Response.Redirect("part1done.asp");

%>;););)

 
Old July 13th, 2004, 04:54 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

Dear Stephan can you post the code here. And one thing that you should post your problem on right topic















Numan
--------------------------------------------------
Love is the most beautiful thing of this world. So do this !
 
Old July 13th, 2004, 07:39 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code

<%@ language = JavaScript%>
<html>
<head>
</head>
<body>
<%
    var month = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    var nowDate = new Date();
    var nowDate = nowDate.getDate() + " " + month[nowDate.getMonth()] + " " + nowDate.getFullYear();
    var orderNo;

    var adoConnection = Server.CreateObject("ADODB.Connection");
    adoConnection.Open("DSN=ComBitsCoDB");
    var adoRecordset;

    var mySQL = "INSERT INTO CustomerOrder " + "(CustomerName, CustomerAddress, TelNumber, OrderDate)";
    mySQL = mySQL + " VALUES ('" + Request.Form("txtCustomerName") + "','";
    mySQL = mySQL + Request.Form("txtCustomerAddress") + "','";
    mySQL = mySQL + Request.Form("txtTelNumber") + "','";
    mySQL = mySQL + nowDate + "')";

    adoConnection.Execute(mySQL);

    mySQL = "SELECT Max(OrderNo) AS MaxOrderNo FROM CustomerOrder WHERE ";
    mySQL = mySQL + " OrderDate = #" + nowDate + "# AND ";
    mySQL = mySQL + " CustomerName = '" + Request.Form("txtCustomerName") + "'";

    adoRecordset = adoConnection.Execute(mySQL);

    orderNo = adoRecordset("MaxOrderNo").Value;

    adoRecordset.Close();
    adoRecordset = null;

    var mySQL = "INSERT INTO OrderItem (OrderNo, StockId, QtyOrdered)";
    mySQL = mySQL + " VALUES (" + orderNo + ",";
    mySQL = mySQL + Request.Form("txtStockId") + ",";
    mySQL = mySQL + "1)";

    adoConnection.Execute(mySQL);

    adoConnection.Close();
    adoConnection = null;

    Response.Write("<h2><center>Your order was completed successfully" + "</center></h2>");
    %>
</body>
</html>

 
Old July 13th, 2004, 09:17 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

I think the problem is with date in the following statement:

mySQL = mySQL + " VALUES ('" + Request.Form("txtCustomerName") + "','";
    mySQL = mySQL + Request.Form("txtCustomerAddress") + "','";
    mySQL = mySQL + Request.Form("txtTelNumber") + "','";
    mySQL = mySQL + nowDate + "')";






Om Prakash
 
Old July 13th, 2004, 09:24 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I beleive the error is in the following section, well i think that's where the error message is pointing to:

r mySQL = "INSERT INTO OrderItem (OrderNo, StockId, QtyOrdered)";
    mySQL = mySQL + " VALUES (" + orderNo + ",";
    mySQL = mySQL + Request.Form("txtStockId") + ",";
    mySQL = mySQL + "1)";

    adoConnection.Execute(mySQL);


 
Old July 13th, 2004, 09:25 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But i have no idea what it could be

 
Old July 13th, 2004, 09:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try printing out what mySQL is, and comment out the line that executes it.

Also, could it be that you didn't quote the '1' at the end of the statement?

HTH,

Snib

<><
 
Old July 13th, 2004, 10:41 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The qoutes didn't change anything. Here is the print out:

INSERT INTO OrderItem (OrderNo, StockId, QtyOrdered) VALUES (18,,1)






Similar Threads
Thread Thread Starter Forum Replies Last Post
NEED HELP INSERT INTO statement syntax error koco ASP.NET 1.0 and 1.1 Basics 6 June 2nd, 2006 04:01 PM
Syntax error in INSERT INTO statement mega ASP.NET 1.0 and 1.1 Basics 3 January 12th, 2005 04:30 PM
Syntax error in INSERT INTO statement. askaggs Classic ASP Databases 5 June 10th, 2004 12:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.