By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

ASP & MS ACCESS if condition error ?

Fary4u
100+
P: 273
Hi i've got this following error any body knows how to overcome this coz it's waste my 3 hours

Error Type:
Microsoft VBScript compilation (0x800A03F6)
Expected 'End'

line 58

is my if condition have something wrong ?

it's multiple data entry record into the database ?

Expand|Select|Wrap|Line Numbers
  1. <%
  2. pnam=Trim(request("txtpname"))
  3. Set objConn = Server.CreateObject("ADODB.Connection")
  4. objConn.open . . . . MS ACCESS
  5. set objrs = server.createObject("ADODB.RecordSet")
  6. objrs.open "Select productName from products where productName='" & pnam & "'",objConn,Adopendynamic,Adlockoptimistic
  7. if objrs.eof then
  8.  
  9.     pnam=Trim(request("txtpname"))
  10.     tdes=Trim(request("txtdesc"))
  11.     prid=Trim(request("txtpid"))
  12.  
  13.         if (categ = "") then
  14.         response.redirect "ul_add.asp"
  15.         end if
  16.  
  17.             objrs.Addnew
  18.                 objrs("productName")=pnam
  19.                 objrs("productDesc")=tdes                                
  20.             objrs.update
  21.  
  22.             st2 = Request.Form("10")
  23.             st3 = Request.Form("12")
  24.             ct1 = Request.Form("black")
  25.             ct2 = Request.Form("blue")
  26.  
  27.     Set Conn = Server.CreateObject("ADODB.Connection")
  28.     Conn.Open ConString    
  29.  
  30.         If st1 = "10" Then
  31.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  32.                     & " (size_id, prod_id) values " _ 
  33.                     & " ('10',"&prid&")"
  34.                 Conn.Execute(sqlText)
  35.         else if st2 = "12" Then
  36.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  37.                     & " (size_id, prod_id) values " _ 
  38.                     & " ('12',"&prid&")"
  39.                 Conn.Execute(sqlText)
  40.         else if ct1 = "black" Then
  41.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  42.                 & " (color_id, prod_id) values " _ 
  43.                 & " ('black',"&prid&")"
  44.             Conn.Execute(sqlText)
  45.         else if ct2 = "blue" Then
  46.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  47.                 & " (color_id, prod_id) values " _ 
  48.                 & " ('blue',"&prid&")"
  49.             Conn.Execute(sqlText)
  50.         response.write "New Record save in the Database"
  51. else
  52.         response.write "This Record already in a Database"
  53. end if
  54.  
  55. objrs.close
  56. set objrs= Nothing
  57. objConn.Close
  58. set objConn = Nothing
  59. %>
  60.  
any solution for that ?
Oct 18 '07 #1
Share this Question
Share on Google+
9 Replies


markrawlingson
Expert 100+
P: 346
Look at this block of code...

Expand|Select|Wrap|Line Numbers
  1.         If st1 = "10" Then
  2.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  3.                     & " (size_id, prod_id) values " _ 
  4.                     & " ('10',"&prid&")"
  5.                 Conn.Execute(sqlText)
  6.         else if st2 = "12" Then
  7.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  8.                     & " (size_id, prod_id) values " _ 
  9.                     & " ('12',"&prid&")"
  10.                 Conn.Execute(sqlText)
  11.         else if ct1 = "black" Then
  12.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  13.                 & " (color_id, prod_id) values " _ 
  14.                 & " ('black',"&prid&")"
  15.             Conn.Execute(sqlText)
  16.         else if ct2 = "blue" Then
  17.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  18.                 & " (color_id, prod_id) values " _ 
  19.                 & " ('blue',"&prid&")"
  20.             Conn.Execute(sqlText)
  21.         response.write "New Record save in the Database"
  22. else
  23.         response.write "This Record already in a Database"
  24. end if
  25.  
  26.  
Replace it with the following (i pointed out the error here too)

Expand|Select|Wrap|Line Numbers
  1.         If st1 = "10" Then '<-- the code is expecting an end to this statement
  2.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  3.                     & " (size_id, prod_id) values " _ 
  4.                     & " ('10',"&prid&")"
  5.                 Conn.Execute(sqlText)
  6.         else if st2 = "12" Then
  7.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  8.                     & " (size_id, prod_id) values " _ 
  9.                     & " ('12',"&prid&")"
  10.                 Conn.Execute(sqlText)
  11.         else if ct1 = "black" Then
  12.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  13.                 & " (color_id, prod_id) values " _ 
  14.                 & " ('black',"&prid&")"
  15.             Conn.Execute(sqlText)
  16.         else if ct2 = "blue" Then
  17.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  18.                 & " (color_id, prod_id) values " _ 
  19.                 & " ('blue',"&prid&")"
  20.             Conn.Execute(sqlText)
  21.         end if '<---- was missing
  22.         response.write "New Record save in the Database"
  23. else
  24.         response.write "This Record already in a Database"
  25. end if '<--- Is the end to another If statement further up in the code.
  26.  
Sincerely,
Mark
Oct 18 '07 #2

Fary4u
100+
P: 273
Thx for you kindly reply i've tryied that but the error i've found it on else statment when it's finally going to b finished ?

Line 23 the new code

? ? ? ? ? ? ? i don't know why ?

Regards
Farhan
Oct 19 '07 #3

Ranjan kumar Barik
P: 95
Thx for you kindly reply i've tryied that but the error i've found it on else statment when it's finally going to b finished ?

Line 23 the new code

? ? ? ? ? ? ? i don't know why ?

Regards
Farhan
Hi , Farhan
Just put the "End If" after Line 25 and see what happens.

Thanks
Oct 22 '07 #4

codegecko
Expert 100+
P: 533
Hi Fary,

You might want to use Select Case to simplify your code instead of If and ElseIf. That way, (I personally find) it's easier to track any problematic code instead of trying to match opening and closing If... End If statements.

Best regards,

medicineworker
Oct 22 '07 #5

Fary4u
100+
P: 273
Hi thx for the reply if i'm gonna try the case condition then it's skip few points which i'm trying to save into the database ?

so i just want to store it to selection if condition coz i think so it's more apporiate then case but any thing else is worng ?

coz i've tryed all possiblities but only give this error ?

Error Type:
Microsoft VBScript compilation (0x800A03F6)
Expected 'End'
/shop/admin/ul_confirm.asp, line ( last else statment )?
Oct 22 '07 #6

markrawlingson
Expert 100+
P: 346
It may also be your if...else.. statement.

If...else... statements in ASP are not written with a space between them(Else If), they're written together (ElseIf). If they're written apart - I believe ASP may interpret them to be a seperate if statement, which also requires an end if statement. So ASP thinks you've got FOUR if statements here, not one else...if.. and is looking for an end if for all of them.

Expand|Select|Wrap|Line Numbers
  1. If whatever = whatever Then
  2. 'do whatever
  3. Else If whatever <> whatever then
  4. 'do something else
  5. end if
  6.  
  7. 'the above is the equivelant to the following..
  8.  
  9. If Whatever = whatever Then
  10. 'do whatever
  11. Else
  12.    If whatever <> whatever then
  13.      'do whatever
  14.    End If
  15.  
  16. 'See the missing end if? That's what ASP sees.
  17.  
Try the following code::

Expand|Select|Wrap|Line Numbers
  1. <%
  2. pnam=Trim(request("txtpname"))
  3. Set objConn = Server.CreateObject("ADODB.Connection")
  4. objConn.open . . . . MS ACCESS
  5. set objrs = server.createObject("ADODB.RecordSet")
  6. objrs.open "Select productName from products where productName='" & pnam & "'",objConn,Adopendynamic,Adlockoptimistic
  7. if objrs.eof then
  8.  
  9.     pnam=Trim(request("txtpname"))
  10.     tdes=Trim(request("txtdesc"))
  11.     prid=Trim(request("txtpid"))
  12.  
  13.         if (categ = "") then
  14.         response.redirect "ul_add.asp"
  15.         end if
  16.  
  17.             objrs.Addnew
  18.                 objrs("productName")=pnam
  19.                 objrs("productDesc")=tdes                        
  20.             objrs.update
  21.  
  22.             st2 = Request.Form("10")
  23.             st3 = Request.Form("12")
  24.             ct1 = Request.Form("black")
  25.             ct2 = Request.Form("blue")
  26.  
  27.     Set Conn = Server.CreateObject("ADODB.Connection")
  28.     Conn.Open ConString 
  29.  
  30.         If st1 = "10" Then
  31.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  32.                     & " (size_id, prod_id) values " _ 
  33.                     & " ('10',"&prid&")"
  34.                 Conn.Execute(sqlText)
  35.         elseif st2 = "12" Then
  36.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  37.                     & " (size_id, prod_id) values " _ 
  38.                     & " ('12',"&prid&")"
  39.                 Conn.Execute(sqlText)
  40.         elseif ct1 = "black" Then
  41.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  42.                 & " (color_id, prod_id) values " _ 
  43.                 & " ('black',"&prid&")"
  44.             Conn.Execute(sqlText)
  45.         elseif ct2 = "blue" Then
  46.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  47.                 & " (color_id, prod_id) values " _ 
  48.                 & " ('blue',"&prid&")"
  49.             Conn.Execute(sqlText)
  50.         end if
  51.         response.write "New Record save in the Database"
  52. else
  53.         response.write "This Record already in a Database"
  54. end if
  55.  
  56. objrs.close
  57. set objrs= Nothing
  58. objConn.Close
  59. set objConn = Nothing
  60. %>
  61.  
You wouldn't be able to use a Select case statement here. Select statements check the value of 1 variable, and do different things depending on what the value of that variable is. In each section of your if...else statement here you're checking a different variable, so a case statement would not be effective.

Try the code above and see if it works, the bottom line here is that ASP IS looking for an ending to one of your If statements, you just have to find where. I believe I've found it in the above code... so see if that works.

Sincerely,
Mark
Oct 22 '07 #7

Fary4u
100+
P: 273
thanks for every body who's replying on this post

Marks you've rite if condition has some problem when i use
Expand|Select|Wrap|Line Numbers
  1.  elseif 
all together it's execuate all my code but it's only store the 1st value & then next values it's just skip the all values of my program


it mean after taking elseif it's jumped into the last endif statement but i want to use the other as well ?

please any body have some solution how to overcome this problem for the last many dayz i've ?

best regards
Farhan
Oct 23 '07 #8

markrawlingson
Expert 100+
P: 346
Yeah, of course it will.

IF...ELSE statements are kind of like saying "If today is saturday, go partying, otherwise.. go to work."

Otherwise, being the keyword here.

You're basically saying If st1 = "10" Then - insert a record, otherwise (if st1 does NOT equal "10", then check to see if st2 = "12", if it is... insert a record pertinant to that variable.... If st2 does NOT equal "12" then check to see if ct1 = "black" - if it is, insert a record.. etc etc.

What you want to do is check each one individually.
See the below code.

Expand|Select|Wrap|Line Numbers
  1. <%
  2.         If st1 = "10" Then
  3.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  4.                     & " (size_id, prod_id) values " _ 
  5.                     & " ('10',"&prid&")"
  6.                 Conn.Execute(sqlText)
  7.         End If
  8.         If st2 = "12" Then
  9.                 sqlText = "INSERT INTO PRODUCT_SIZES " _
  10.                     & " (size_id, prod_id) values " _ 
  11.                     & " ('12',"&prid&")"
  12.                 Conn.Execute(sqlText)
  13.         End If
  14.         If ct1 = "black" Then
  15.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  16.                 & " (color_id, prod_id) values " _ 
  17.                 & " ('black',"&prid&")"
  18.             Conn.Execute(sqlText)
  19.         End If
  20.         If ct2 = "blue" Then
  21.             sqlText = "INSERT INTO PRODUCT_COLOURS " _
  22.                 & " (color_id, prod_id) values " _ 
  23.                 & " ('blue',"&prid&")"
  24.             Conn.Execute(sqlText)
  25.         End If
  26. %>
  27.  
This is different because it says,

If st1 = "10" - add a record - if it isn't, don't add a record
If st2 = "12" - add a record - if it isn't, don't add a record
If ct1 = "black" - add a record - if it isn't, don't add a record
etc.

Sincerely,
Mark
Oct 24 '07 #9

Fary4u
100+
P: 273
Hi Marks thx for you replying
and all other how make contribution on this discussion

my coding is working fine thx for the discussion
can you please take a look this code as well any idea about that ?
http://www.thescripts.com/forum/thread695688.html

regards
Farhan
Oct 24 '07 #10

Post your reply

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