473,419 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

asp if statements with hyperlinks

17
Hi there,

I can't seem to find the proper syntax for my if statement when I have a list of links and depending on which link the administrator selects the mysql table will show up on the page it is redirected to.

All my links will be redirected to the same page, but I need to put in several if statements that I thought would be quite easy, but keep receiving syntax errors.

Here's my code if you can see the problem:

<%Dim conn
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=mona.ramsay;PWD=puke_9;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")


If selected = <a href="http://localhost/ValourCommunityCentre/PageItems.asp"><strong><span style="font-size: 16pt">
Community Club Table</span></strong></a><br /> then

sql = "SELECT * FROM CCtable"
end if

If selected = <a href="http://localhost/ValourCommunityCentre/PageItems.asp"><strong><span style="font-size: 16pt">
User Table</span></strong></a><br /> then
sql = "SELECT * FROM Usertable"
end if
<br />

rs.Open sql, conn

Any help would be appreciated.

M
Aug 25 '07 #1
9 1857
ilearneditonline
130 Expert 100+
Your links should be more link this. Because you need to be passing a parameter.

[HTML]<a href="http://localhost/ValourCommunityCentre/PageItems.asp?LinkChosen=club"> Community Club</a>
<a href="http://localhost/ValourCommunityCentre/PageItems.asp?LinkChosen=user"> Users</a>
[/HTML]
Then you request.querystring the "LinkChosenValue"

Expand|Select|Wrap|Line Numbers
  1. Dim selected, query
  2. ' get the item that was passed in the querystring.
  3. selected = Request.QueryString("LinkChosen");
  4.  
  5. ' i assumed you would have more than 1 or 2 links 
  6. Select Case selected
  7. Case "club"
  8. query = "SELECT * FROM CCtable"
  9. Case "user"
  10. query = "SELECT * FROM UserTable"
  11. Case Else
  12. query = ""
  13. End Select
  14.  
Aug 26 '07 #2
mramsay
17
Hi there,

I changed my code, but now I keep receiving an error for my response.write code. It worked before, but now I receive the error.

Expected statement
/ValourCommunityCentre/PageItems.asp, line 56
<td> Response.write(x.value)</td>

This is my code:

<%Dim selected, query
' get the item that was passed in the querystring.
selected = Request.QueryString("LinkChosen")

' i assumed you would have more than 1 or 2 links
Select Case selected
Case "club"
query = "SELECT * FROM CCtable"
Case "user"
query = "SELECT * FROM UserTable"
Case Else
query = ""
End Select%>




<% rs.Open sql, conn%>


<table border="1" width="100%">

<tr>
<% for each x in rs.fields
response.write("<th>" & x.name & " </th>")
next%>

</tr>
<% do until rs.EOF

for each x in rs.fields%>

<%<td> Response.write(x.value)</td>%>
<%next
rs.movenext

loop

rs.close
conn.close
%>

</table>

I think it has something to do with my asp tags, but can't figure it out.
Aug 28 '07 #3
bakpao
21
Try

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Response.Write "<td>" & x.value & "</td>"
  3. %>
  4.  
Aug 28 '07 #4
mramsay
17
Hello,

I keep receiving an error message when I select a link it is supposed to redirect to a pageitems.asp. I will have several links, but am just testing two right now.

I am using the select caes code, but keep receiving this error:

Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/ValourCommunityCentre/PageItems.asp, line 28


Here is my code:

<%Dim conn
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=mona.ramsay;PWD=puke_9;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")%>

<%Dim selected, query
' get the item that was passed in the querystring.
selected = Request.QueryString("LinkChosen")

rs.Open sql, conn

' i assumed you would have more than 1 or 2 links
Select Case selected
Case "club"
query = "SELECT * FROM CCtable"
Case "user"
query = "SELECT * FROM UserTable"
Case Else
query = ""
End Select%>







<table border="1" width="100%">

<tr>
<% for each x in rs.fields
response.write("<th>" & x.name & " </th>")
next%>

</tr>
<% do until rs.EOF%>
<tr>
<%for each x in rs.fields

Response.Write "<td>" & x.value & "</td>"%>

<% next
rs.movenext%>

</tr>

<%loop

rs.close
conn.close
%>

</table>

Could someone please take a look at it and see why I keep receiving the error??
I've gotten over other errors, but can't seem to figure this one out.

Thanks,
Mona
Aug 30 '07 #5
ilearneditonline
130 Expert 100+
Expand|Select|Wrap|Line Numbers
  1.  rs.Open sql, conn 
  2.  
  3. ' i assumed you would have more than 1 or 2 links 
  4. Select Case selected
  5. Case "club"
  6. query = "SELECT * FROM CCtable"
  7. Case "user"
  8. query = "SELECT * FROM UserTable"
  9. Case Else
  10. query = ""
  11. End Select%>
  12.  
Well, you are doing an rs.Open sql, conn but sql does not appear anywhere in the code you provided. I would think you really mean rs.Open query, conn. But you would need to put that after the Select Case, else it is an empty variable.
Aug 30 '07 #6
mramsay
17
Hi there,

I am still having problems with errors and can't display my page.

Now, I receive this error. I tried to debug, but can't figure it out.

ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.

My code:

<%Dim conn
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=mona.ramsay;PWD=puke_9;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")%>

rs.Open query, conn

<%Dim selected, query
' get the item that was passed in the querystring.
selected = Request.QueryString("LinkChosen")



' i assumed you would have more than 1 or 2 links
Select Case selected
Case "club"
query = "SELECT * FROM CCtable"
Case "user"
query = "SELECT * FROM UserTable"
Case Else
query = ""
End Select%>







<table border="1" width="100%">

<tr>
<% for each x in rs.fields
response.write("<th>" & x.name & " </th>")
next%>

</tr>
<% do until rs.EOF%>
<tr>
<%for each x in rs.fields

Response.Write "<td>" & x.value & "</td>"%>

<% next
rs.movenext%>

</tr>

<%loop%>

<%rs.close
conn.close
%>
Aug 31 '07 #7
markrawlingson
346 Expert 100+
<%Dim conn
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=mona.ramsay;PWD=puke_9;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")%>

rs.Open query, conn

<%Dim selected, query
' get the item that was passed in the querystring.
selected = Request.QueryString("LinkChosen")
Where is your query?

You open a connection object, then set your recordset object and open it with "query" - but "query" is set with Select Case AFTER you open your recordset. Execution of an ASP page happens from top to bottom, like you would read a book. So at the point in time that you are trying to open your recordset object "query" is null, or equal to "" - therefore you are passing an invalid, or empty, query to your database. Your recordset doesn't get opened.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim conn 
  3. 'Create an ADODB connection
  4. Set conn = Server.CreateObject("ADODB.Connection")
  5.  
  6. 'Open the database
  7. conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=mona.ramsay;PWD=puke_9;"
  8.  
  9. 'Execute the SQL and assign to our Recordset
  10. set rs = Server.createobject("ADODB.recordset")%>
  11.  
  12. Dim selected, query
  13. ' get the item that was passed in the querystring.
  14. selected = Request.QueryString("LinkChosen")
  15.  
  16. ' i assumed you would have more than 1 or 2 links 
  17. Select Case selected
  18. Case "club"
  19. query = "SELECT * FROM CCtable"
  20. Case "user"
  21. query = "SELECT * FROM UserTable"
  22. Case Else
  23. query = ""
  24. End Select
  25.  
  26. rs.Open query, conn
  27.  
  28. %>
  29.  
  30.  
I moved your recordset open statement to AFTER the query string variable is set. So...

1) your connection object is created
2) your connection object is opened
3) your recordset object is created
4) your query is set, depending on what url the visitor selected
5) your recordset object is opened and your query is passed into it to grab information from the database.

Mark
Aug 31 '07 #8
mramsay
17
Hi there,

I moved my open recordset and it worked.

Thank you very much.

Mona
Sep 5 '07 #9
I recently had to use a select statement with 40 different outcomes where on analysis of what came back from the database I fed differing strings into a variable which displayed different buttons going to different pages displaying different messages on hover over the button. I also fed variables into the variable itself . Worked really well, let me know if you would like the code.

Steve M
Sep 8 '07 #10

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

Similar topics

6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
4
by: Seefor | last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did this which works fine: a, a:link, a:visited, a:hover, a:active { color: #000; text-decoration: none;
1
by: Robin | last post by:
Hello! I'm having trouble with links and hyperlinks in MS Access 2003 - any help would be great! Question 1! The "insert hyperlink" icon opens a browser window, allows the user to browse...
1
by: Janna | last post by:
Hello tech savvy gurus! I hope someone can help me! THE PROBLEM: "Cannot open specified file" when I click on a hyperlink in an Access database when it is located on our server. THE...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.