Print Page | Close Window

Trouble with INSERT INTO table

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=8283
Printed Date: 01 April 2026 at 1:14am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Trouble with INSERT INTO table
Posted By: joshualane
Subject: Trouble with INSERT INTO table
Date Posted: 22 December 2003 at 9:57am
I'm having some trouble with my code and I'm not sure what the issue is. Basically, I have a form that is passing the information on to another asp page in order to add the info to the database. The error that I'm getting states:

Number of query values and destination fields are not the same


I checked the code, but don't know what the issue is? I'm guessing it's something to do with the two date values, but I'm not sure.


StrSql = "INSERT INTO Clients (CLIENT_NAME, CLIENT_STREET, CLIENT_CITY, CLIENT_ZIP, CLIENT_PHONE, CLIENT_GeneratorID, CLIENT_StartDATE, CLIENT_StopDATE, CLIENT_DESC) VALUES ('" & chkString(request("NAME")) & "', '" & chkString(request("STREET")) & "', '" & chkString(request("CITY")) & "', '" & chkString(request("STATE")) & "', '" & chkString(request("ZIP")) & "', '" & chkString(request("PHONE")) & "', '" & chkString(request("GeneratorID")) & "', '" & chkString(request("StartDATE")) & "', '" & chkString(request("StopDATE")) & "', '" & chkString(request("DESC")) & "')"



Replies:
Posted By: joshualane
Date Posted: 22 December 2003 at 10:40am
Never mind... I found a better way to handle the process thanks to a http://www.webwiz.net/asp/tutorials/add_to_database_pt2.asp - Web Wiz tutorial .



Posted By: MorningZ
Date Posted: 22 December 2003 at 3:53pm

and for future reference...

"Number of query values and destination fields are not the same"

means that the # of items don't match, so in

INSERT INTO table (....these column names...) VALUES (...these values....)

don't have the same number or items, and directly from the code you posted:

Items in Column Name section of Insert:
CLIENT_NAME
CLIENT_STREET
CLIENT_CITY
CLIENT_ZIP
CLIENT_PHONE
CLIENT_GeneratorID
CLIENT_StartDATE
CLIENT_StopDATE
CLIENT_DESC

(9 items total)

Items in right side:
chkString(request("NAME"))
chkString(request("STREET"))
chkString(request("CITY"))
chkString(request("STATE"))
chkString(request("ZIP"))
chkString(request("PHONE"))
chkString(request("GeneratorID"))
chkString(request("StartDATE"))
chkString(request("StopDATE"))
chkString(request("DESC"))

(10 items)

since 9 != 10, SQL spit out that error and told you exactly what's wrong :)

 



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: joshualane
Date Posted: 22 December 2003 at 4:40pm
Yeah, I figured that out too once I started messing with the code some more. Oh well, perhaps next time I won't be so absent-minded and miss the completely obvious. Thanks for your help though, I appreciate it.


Posted By: MorningZ
Date Posted: 22 December 2003 at 6:19pm

nothing to be absent minded about...

just trust the error messages, read what they are telling you.....  makes programming a lot easier



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: psycotik
Date Posted: 22 December 2003 at 10:53pm

Also another thing is not to be afraid to divide the string into multiple lines.

sql = sql & "..."
sql = sql & "..."
sql = sql & "..."

Makes the sql alot easier to read/understand + change




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net