Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old November 26th, 2006, 12:53 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I get the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

/signGuestbook.asp, line 44


It points to the "adoConnection.Execute(mySQL);" line. Attached is my most recently revised code that generated this error:

Code:
<%@ LANGUAGE = JavaScript%>
<html>
<head>
<title>Sign Guestbook</title>
</head>
<body>
<%
  var adoConnection = Server.CreateObject("ADODB.Connection");
  adoConnection.Open("DSN=MusicDb");
  var adoRecordset;
  var d = new Date();
  d = (d.getMonth() + 1) + "-" + d.getDate() + "-" + d.getFullYear();
  var n, e, w, m; 
  n = Request.Form("name");
  e = Request.Form("email");
  w = Request.Form("website");
  m = Request.Form("msg"); 

/*  var mySQL = "INSERT INTO Guestbook " + 
      "(Date, Name, Email, Website, Msg)";
   mySQL = mySQL + " VALUES ('" + d + "','";
   mySQL = mySQL + Request.Form("name") + "','";
   mySQL = mySQL + Request.Form("email") + "','";
   mySQL = mySQL + Request.Form("website") + "','";
   mySQL = mySQL + Request.Form("msg") + "','";
   mySQL = mySQL + "')";
*/
   var mySQL = "INSERT INTO [Guestbook] ([Date]," 
            + " [Name]," 
            + " [Email]," 
            + " [Website],"  
            + " [Msg])" 
            + " VALUES ('" + d + "'" 
            + ", '" + n + "'" 
            + ", " + e
            + ", '" + w + "'" 
            + ", '" + m + "')";

 /* var mysql = "insert into Guestbook " + "(Date, Name, Email, Website, Msg)" + " values ('";
  mysql = mysql + d + "','";
  mysql = mysql + n + "','" + e + "','" + w + "','" + m;
  mysql = mysql + "')"; */

  adoConnection.Execute(mySQL);

  Response.Write ("You have added the following entry to the guestbook.<br /><br />");
  var newsql = "select * from guestbook where Name = n";
  adoRecordset = adoConnection.Execute(newsql);

  while (adoRecordset.Eof == false)
  {
  %>
    <p>
    Date: <%=adoRecordset("Date").Value%><br />
    Name: <%=adoRecordset("Name").Value%><br />
    Email: <%=adoRecordset("Email").Value%><br />
    Message: <%=adoRecordset("Msg").Value%><br />
    </p>
  <%
    adoRecordset.MoveNext();
  }

  adoRecordset.Close();
  adoRecordset = null;
  adoConnection.Close();
  adoConnection = null;
 
%>
</body>
</html>
Sorry to be such a pest

Reply With Quote
  #12 (permalink)  
Old November 26th, 2006, 11:04 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Syster Tara
var mySQL = "INSERT INTO [Guestbook] ([Date],"
            + " [Name],"
            + " [Email],"
            + " [Website],"
            + " [Msg])"
            + " VALUES ('" + d + "'"
            + ", '" + n + "'"
            + ", " + e
            + ", '" + w + "'"
            + ", '" + m + "')";
It looks like the email variable(e) is no longer enclosed in single quotes as it was in the earlier code.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #13 (permalink)  
Old November 27th, 2006, 07:50 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Syster Tara

When I ask a question that gets ignored I tend to sway from a post. Take woodyz advise on your naming of field names. There are very few 'Reserved Words' you should steer clear of. There are very good reasons for this, and so so many others to choose from. Yes you can use [] but why? For a full list of reserved words ask google 'access reserved words' FYI 'Date' is one of them no matter what version you are using.

Wind is your friend
Matt
Reply With Quote
  #14 (permalink)  
Old November 29th, 2006, 04:23 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I still get too few parameters, even after changing "Date" to "EntryDate" in both the db and asp script.

I have uploaded a screencap of my guestbook structure with field names and stuff at http://www.tarasdemos.com/images/guestbook.gif, so please look at it and then look at my code and see if everything looks correct to you as it does to me.

Here is yet another look at my script after the above changes were made:

Code:
<%@ LANGUAGE = JavaScript%>
<html>
<head>
<title>Sign Guestbook</title>
</head>
<body>
<%
  var adoConnection = Server.CreateObject("ADODB.Connection");
  adoConnection.Open("DSN=MusicDb");
  var adoRecordset;
  var d = new Date();
  d = (d.getMonth() + 1) + "-" + d.getDate() + "-" + d.getFullYear();
  var n, e, w, m; 
  n = Request.Form("name");
  e = Request.Form("email");
  w = Request.Form("website");
  m = Request.Form("msg"); 

/*  var mySQL = "INSERT INTO Guestbook " + 
      "(EntryDate, Name, Email, Website, Msg)";
   mySQL = mySQL + " VALUES ('" + d + "','";
   mySQL = mySQL + Request.Form("name") + "','";
   mySQL = mySQL + Request.Form("email") + "','";
   mySQL = mySQL + Request.Form("website") + "','";
   mySQL = mySQL + Request.Form("msg") + "','";
   mySQL = mySQL + "')";
*/
   var mySQL = "INSERT INTO [Guestbook] ([EntryDate]," 
            + " [Name]," 
            + " [Email]," 
            + " [Website],"  
            + " [Msg])" 
            + " VALUES ('" + d + "'"
            + ", '" + n + "'" 
            + ", '" + e + "'"
            + ", '" + w + "'" 
            + ", '" + m + "')";

 /* var mysql = "insert into Guestbook " + "(EntryDate, Name, Email, Website, Msg)" + " values ('";
  mysql = mysql + d + "','";
  mysql = mysql + n + "','" + e + "','" + w + "','" + m;
  mysql = mysql + "')"; */

  adoConnection.Execute(mySQL);

  Response.Write ("You have added the following entry to the guestbook.<br /><br />");
  var newsql = "select * from guestbook where Name = n";
  adoRecordset = adoConnection.Execute(newsql);

  while (adoRecordset.Eof == false)
  {
  %>
    <p>
    Date: <%=adoRecordset("EntryDate").Value%><br />
    Name: <%=adoRecordset("Name").Value%><br />
    Email: <%=adoRecordset("Email").Value%><br />
    Message: <%=adoRecordset("Msg").Value%><br />
    </p>
  <%
    adoRecordset.MoveNext();
  }

  adoRecordset.Close();
  adoRecordset = null;
  adoConnection.Close();
  adoConnection = null;
 
%>
</body>
</html>
Reply With Quote
  #15 (permalink)  
Old November 29th, 2006, 05:47 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well. First of all, please let me know if it is still the same line of code that is causing the error, just to make sure.

The error "Too Few Parameters" usually points to a misspelled column name. It looks like you are not having that, but to make sure, you might want to output the mySql string that is created and run that directly in Access to see if any error occur there.





Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #16 (permalink)  
Old November 30th, 2006, 08:07 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, I finally got it to add the entry to the guestbook, but now it's fussing about "too few parameters" in this other line (in bold):

Code:
var newsql = "select * from Guestbook where Name = n";
Response.Write (newsql);
adoRecordset = adoConnection.Execute(newsql);
As you can see above, I response.wrote the sql out, and again, I don't see anything wrong with it. Can your eagle eyes spot anything?

Reply With Quote
  #17 (permalink)  
Old November 30th, 2006, 08:10 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Syster Tara
 OK, I finally got it to add the entry to the guestbook, but now it's fussing about "too few parameters" in this other line (in bold):

Code:
var newsql = "select * from Guestbook where Name = n";
Response.Write (newsql);
adoRecordset = adoConnection.Execute(newsql);
As you can see above, I response.wrote the sql out, and again, I don't see anything wrong with it. Can your eagle eyes spot anything?

Okay - I bet we are seeing the same problem... try
Code:
var newsql = "select * from Guestbook where [Name] = '" + n + "'";
Response.Write (newsql);
adoRecordset = adoConnection.Execute(newsql);
Or soemthing like that.


Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #18 (permalink)  
Old November 30th, 2006, 08:32 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;As you can see above, I response.wrote the sql out
We want to see what the browser outputs not the line of code which executes the output

You have not taken advice given. Why use Acess Reserved words as field names?? You can
use them however here is a full list of the words you should not use:
http://support.microsoft.com/kb/286335

Your query:
var newsql = "select * from Guestbook where Name = n";
Change it to (note inclusion of single quotes for a string field comparison and move the semi colon inside your string):
var newsql = "select * from Guestbook where Name = 'n';"


Wind is your friend
Matt
Reply With Quote
  #19 (permalink)  
Old November 30th, 2006, 08:38 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Syster Tara

If 'n' is a variable use the syntax Woody posted however if its a hard coded string comparison keep it where it is but sourround it in single quotes, exactly as suggested in my last post. Either way, using ASP and SQL place the semi colon inside your string.

Wind is your friend
Matt
Reply With Quote
  #20 (permalink)  
Old November 30th, 2006, 11:09 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mat41
 Syster Tara

If 'n' is a variable use the syntax Woody posted however if its a hard coded string comparison keep it where it is but sourround it in single quotes, exactly as suggested in my last post. Either way, using ASP and SQL place the semi colon inside your string.

Wind is your friend
Matt
Well... n is a variable:
Code:
n = Request.Form("name");
And since Javascript is being used here as the server side language, the semicolon is the line terminator for this code.

Of course, if this was VBScript, the semi-color would give an error.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in SQL syntax phantom3008 ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2007 07:00 AM
Example SQL causes syntax error Tom Rigby BOOK: Beginning SQL 1 April 18th, 2007 09:32 AM
SQL syntax error - Chapter 3 cutthroatchemist BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 January 15th, 2007 06:19 PM
Syntax error on SQL statement Chris1 Access VBA 1 September 7th, 2004 07:47 AM
$sql="CREATE TABLE syntax error cedtech23 Beginning PHP 3 August 24th, 2004 04:56 AM



All times are GMT -4. The time now is 06:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.