 |
| Classic ASP Professional For advanced coder questions in ASP 3. 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 Professional 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
|
|
|
|

June 3rd, 2006, 06:06 PM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
2 SQL's possible with an IF?
I am tryimg to execute one of the following codes, based on an if statement:
<%
wpage = request.ServerVariables("HTTP_REFERER")
If wpage = "form1.asp" Then
mySQL = "INSERT INTO tbl_team (tName, tSurname, tAge")
mySQL = mySQL & " VALUES ('" & request.form("tName") & "','" & request.form("tSurname") & "','" & request.form("tAge") & "')"
myRS.Open mySQL, myCon,3,3
myCon.execute(mySQL)
ELSE
mySQL = "INSERT INTO tbl_help (hName, hSurname, hAge")
mySQL = mySQL & " VALUES ('" & request.form("hName") & "','" & request.form("hSurname") & "','" & request.form("hAge") & "')"
myRS.Open mySQL, myCon,3,3
myCon.execute(mySQL)
End if
%>
I seem to receive an error:
Number of query values and destination fields are not the same. 
Anyone know where am I going wrong? Hope to hear.
|
|

June 4th, 2006, 05:16 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
There may be an error in the SQL. Instead of executing it, try this (both in the If and the Else):
' myCon.execute(mySQL)
Response.Write("Sql is " & mySQL)
Response.End
What do you get on the screen when you run this?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

June 4th, 2006, 06:21 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hmmm, interesting.
I can see the SQL statement (with all the values I inserted in the form) and it uses the relevant SQL depending on which page is submitted.
So, what does that mean then?
(Thanks for responding too!)
|
|

June 4th, 2006, 06:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
That was the idea of the code I added. By response.writing out your SQL statement, you can diagnose it and check for errors.
Can you post the outcome here so I can take a look?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

June 4th, 2006, 07:01 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, this is the original (i've just put in initials in the form:
Sql is INSERT INTO tbl_Br (BrfName, BrSurname, BrAge, BrStatus, BrEmail, BrPhone, BrTown, BrCountry, BrNational, BrEducation, BrPract, BrWork, BroDesc) VALUES ('N','S','1','Single','E','0','T','GB','N','GCSE', 'Yes','FullTime','PS')
And if it comes from ANOTHER FORM then:
Sql is INSERT INTO tbl_Sr (SrfName, SrSurname, SrAge, SrStatus, SrEmail, SrPhone, SrTown, SrCountry, SrNational, SrEducation, SrPract, SrWork, SroDesc) VALUES ('S1','S2','3','Single','SE','01','ST','GB','SN',' GCSE','Yes','FullTime','Test2')
Hope to hear more...
|
|

June 4th, 2006, 07:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
From what I can see, I don;t think this SQL statement would cause the error you're getting. I see the same number of columns and values.
However, you enclose all your data values in quotes, which won't work for numeric fields. Are you sure, for example, that BrAge is a text type in the database?
And did you try executing this SQL statement that you posted? Maybe this one works, but fields that contain a ' don't....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

June 4th, 2006, 07:23 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
All fields are text fields (apart from the ID=AutoNum)...
The data does no add to the DB...
Here's the uncut/unmodified version (as approved by the client to post):
<%
wpage = request.ServerVariables("HTTP_REFERER")
mypage = Right(wpage, 10)
If mypage = "sister.asp" Then
mySQL = "INSERT INTO tbl_sister (SrfName, SrSurname, SrAge, SrStatus, SrEmail, SrPhone, SrTown, SrCountry, SrNational, SrEducation, SrPract, SrDawah, SrHijab, SrWork, SroDesc)"
mySQL = mySQL & " VALUES ('" & request.form("SrfName") & "','" & request.form("SrSurname") & "','" & request.form("SrAge") & "','" & request.form("SrStatus") & "','" & request.form("SrEmail") & "','" & request.form("SrPhone") & "','" & request.form("SrTown") & "','" & request.form("SrCountry") & "','" & request.form("SrNational") & "','" & request.form("SrEducation") & "','" & request.form("SrPract") & "','" & request.form("SrDawah") & "','" & request.form("SrHijab") & "','" & request.form("SrWork") & "','" & request.form("SroDesc") & "')"
' myCon.execute(mySQL)
Response.Write("Sql is " & mySQL)
Response.End
ELSE
mySQL = "INSERT INTO tbl_brother (BrfName, BrSurname, BrAge, BrStatus, BrEmail, BrPhone, BrTown, BrCountry, BrNational, BrEducation, BrPract, BrDawah, BrBeard, BrWork, BroDesc)"
mySQL = mySQL & " VALUES ('" & request.form("BrfName") & "','" & request.form("BrSurname") & "','" & request.form("BrAge") & "','" & request.form("BrStatus") & "','" & request.form("BrEmail") & "','" & request.form("BrPhone") & "','" & request.form("BrTown") & "','" & request.form("BrCountry") & "','" & request.form("BrNational") & "','" & request.form("BrEducation") & "','" & request.form("BrPract") & "','" & request.form("BrDawah") & "','" & request.form("BrBeard") & "','" & request.form("BrWork") & "','" & request.form("BroDesc") & "')"
' myCon.execute(mySQL)
Response.Write("Sql is " & mySQL)
Response.End
End IF
%>
???
|
|

June 4th, 2006, 07:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Like I said, I don't see a reason for the error you posted from these SQL statements.
This may be too obvious, but when you say "The data does no add to the DB", did you enable the line that executes the SQL statement again??
If not, change:
' myCon.execute(mySQL)
Response.Write("Sql is " & mySQL)
Response.End
to
myCon.execute(mySQL)
Response.Write("Sql is " & mySQL)
Response.End
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

June 4th, 2006, 07:40 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yep, that now works. I have taken out the following (as you can see from my 1st post):
myRS.Open mySQL, myCon,3,3
Thanks Imaar!
|
|

June 4th, 2006, 07:54 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ooops, back again:
Operation is not allowed when the object is closed.
?
myCon.execute(mySQL)
End IF
myRS.Close
Set myRS = Nothing
myCon.Close
Set myCon = Nothing
%>
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| How to merge 2 sql's |
Dr Robert James |
Beginning PHP |
3 |
December 9th, 2004 02:23 PM |
|
 |