# [web] ASP Question!

## Recommended Posts

I need someone to write out a script of how you would do something like this: http://url.com/default.asp?id=12341324 in ASP. I would have used PHP but the school district that runs the webservers is being stubburn and won't install it.

##### Share on other sites
W3C has tutorials:

http://www.w3schools.com/asp/default.asp

ASP Form Get Tutorial

http://www.w3schools.com/asp/showasp.asp?filename=demo_reqquery

##### Share on other sites
Sander    1332
Ah, beaten to it [smile]

##### Share on other sites
one problem when I look at that I have no idea what it means. So that means I wouldnt be able to figure out how to do what i want. Mainly I am a PHP/MySQL person and I am VERY new to ASP.

##### Share on other sites
It's the same, you'll be calling a variable. I'm also PHP/MySQL oriented. I've been fighting the transition to ASP but I'm finding it almost impossible to apply for other web development related positions at other companies due to my lack of knowledge and experience with the language.

##### Share on other sites
Sander    1332
Well, perhaps you should pay better attention to the ads and have a look out for the words "PHP developer"? That's what my new job's advert said. Also, you could call up the compnay that placed the ad and simply ask "Is this about a PHP or ASP position" and if they say ASP, just tell them you'll be sending in your resume and motivation promptly.

I don't know how it is in the states but there are plenty of PHP positions on this side of the pond.

##### Share on other sites
Wan    1366
Quote:
 Original post by blackbirdblackbird1I need someone to write out a script of how you would do something like this:http://url.com/default.asp?id=12341324

I'd love to give an answer, if only I understood the question. :/
What exactly is it that you want to do?

##### Share on other sites
I attempt most positions, but the two areas I have intrest in (winchester, va that I live in and seattle, wa which would be a nice change of scenary) both tend to use microsoft technologies.

I belive in my current work place I'll stress the importance of diversifying our abilities so I can add the latter to my resume. That will probably hlep to search for php instead of web development, it may save some time.

##### Share on other sites
what i am trying to do is make it so that instead of having an actual physical file for each and every Teacher's webpage it just uses variables like this: http://website.com/default.asp?id=123456 and uses just one template.

Does that clear it up a bit?

##### Share on other sites
Wan    1366
I think it's best to find yourself some ASP tutorials. It's a fairly 'old' scripting language, so there should be tons of learning material online.

Besides if you already familiar with PHP scripting, learning some basic ASP shouldn't be a problem. The syntax (VB) is different, and you have actually less functions to work with, but the idea is the same.

Anyway, to get you started:
<%Option Explicit ' not necessary, but good practiceDim id' get id parameter, in this case we're checking if it's a numberIf IsNumeric(Request("id")) Then	id = CLng(Request("id"))Else	id = 0	End If%><html><body><%Const USE_DATABASE = FalseIf USE_DATABASE Then	' using a database	Dim conn	Dim rs		' initialize connection and recordset	Set conn = Server.CreateObject("ADODB.Connection")	Set rs = Server.CreateObject("ADODB.Recordset")		conn.Open("your connection string here")		rs.Open "SELECT TOP 1 title FROM Table WHERE id = " & id, conn		' if result set contains a record, print it	If Not rs.EOF Then		Response.Write("<h1>" & rs("title") & "</h1>")	End If	rs.Close()Else	' show content based on id (hard-coded)	Select Case id			Case 1:			Response.Write("<h1>This is page one</h1>")		Case 2:			Response.Write("<h1>This is page two</h1>")		Case 3:			Response.Write("<h1>This is page three</h1>")		Case Else			Response.Write("<h1>This is the default page</h1>")				End SelectEnd If%><a href="default.asp">default page</a> | <a href="default.asp?id=1">page one</a> | <a href="default.asp?id=2">page two</a> | <a href="default.asp?id=3">page three</a></body></html>

Note that I haven't tested it, and that it's an extremely simple example.
The code above will parse the id parameter from the querystring and store it in a variable id. How to then use this id is up to you. In my sample I have included two options: one is using a database to select the content to be displayed, the second is using a switch statement and some hard-coded text (notice the constant to switch between these two).

##### Share on other sites
YAY!! So far I have gotten it to work!

I was wondering how would you call a variable that has already been extracted from a database like in PHP: <? \$variable ?> So that you can call it several times outside the php. And how would I change the page title according to the teachers name.

##### Share on other sites
How would you have it display a message if the ID is not found in the database?

##### Share on other sites
Wan    1366
No offense, but I am not going to write all your code. I gave you an example to get you going, but it still requires some effort from you. Like I and others already pointed out, find a book or go through some online tutorials to get a better understanding of ASP.

I'll be a nice guy and answer your last two post: [smile]

Quote:
 Original post by blackbirdblackbird1I was wondering how would you call a variable that has already been extracted from a database like in PHP: So that you can call it several times outside the php. And how would I change the page title according to the teachers name.

You mean who to write to the reponse stream?

<%= myVariable %>

Quote:
 Original post by blackbirdblackbird1How would you have it display a message if the ID is not found in the database?

Take a look at this section of the code. It checks if a record has been found. This is where you can handle your not-found case.

	' if result set contains a record, print it	If Not rs.EOF Then		Response.Write("<h1>" & rs("title") & "</h1>")	End If	' if result set contains a record, print it (NEW VERSION)	If Not rs.EOF Then		Response.Write("<h1>" & rs("title") & "</h1>")	Else		Response.Write("<h1>Entry not found</h1>")	End If

##### Share on other sites

Error Type:ADODB.Field (0x80020009)Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record./faculty/history.asp

I only get this error when there is no entry with that ID.

	Dim conn	Dim rs		' initialize connection and recordset	Set conn = Server.CreateObject("ADODB.Connection")	Set rs = Server.CreateObject("ADODB.Recordset")	conn.Provider="Microsoft.Jet.OLEDB.4.0"		conn.Open("c:/inetpub/ahsftp/AHS/design/faculty/teacher.mdb")		rs.Open "SELECT TOP 1 name, photo, quote, p_1, p_2, p_3, p_4, p_5, p_6, p_7, subject, room, office_hours, voice_mail, email, fav_sports, fav_subj, fav_food, fav_movie, fav_music FROM history WHERE id = " & id, conn		' if result set contains a record, print it (NEW VERSION)	If Not rs.EOF Then		Response.Write("<h1>" & rs("name") & "</h1>")	Else		Response.Write("<h1>Either the Teachers info has not been added yet or you have been given an invalid teacher ID.</h1>")	End If%>

Thanx so much for all your help!

##### Share on other sites
I, like most others here, don't know crap about ASP, but aren't you able to 'select' your programming language, something like: "<script language='x' runat='server'>"? If you like your C-style syntax, you can try using C#, but that doesn't have anything much to do with the question at hand (though, from the ASP code I've seen so far, the methods you have to take to get to that information looks like crap to me).
Or is that ASP.NET-specific?

##### Share on other sites
Wan    1366
Quote:
 Original post by deadimpI, like most others here, don't know crap about ASP, but aren't you able to 'select' your programming language, something like: "

ASP != ASP.NET, ASP is VBScript only.

##### Share on other sites
capn_midnight    1707
Quote:
Original post by WanMaster
Quote:
 Original post by deadimpI, like most others here, don't know crap about ASP, but aren't you able to 'select' your programming language, something like: "

ASP != ASP.NET, ASP is VBScript only.

well, JScript can be used, but it is so poorly documented and supported that it might as well not be available.

##### Share on other sites
How would you make the DATE into a variable? Like take this:
<% Response.Write(Date()) %>

and make it into a variable that can be used for selecting a row from an Access Database.

##### Share on other sites
I think you would just need to diminuate (don't know why they chose that word) and define the variable:
<%Dim xx=Date() 'That, or Set x=New Date(), or however VB works with that%>

This is a VBScript-specific question

##### Share on other sites
Function GuaranteeCLng(sNum, iDefault)
If IsNumeric(sNum) Then
GuaranteeCLng = CLng(sNum)
Else
GuaranteeCLng = iDefault
End If
End Function

'This is a great function for seeing whats going on
Function DisplayRequest()
Dim i
Dim iMax

iMax = Request.ServerVariables.Count
For i = 1 To iMax
Response.Write("")& vbNewLine
Next
iMax = Request.Form.Count
For i = 1 To iMax
Response.Write("")& vbNewLine
Next
iMax = Request.QueryString.Count
For i = 1 To iMax
Response.Write("")& vbNewLine
Next
End Function

'This function shows a date in DD/MM/YYYY format
Function DisplayDate(d)
Dim s

If IsDate(d) Then
If Day(d)<=9 Then
s=s & "0"
End If
s=s & Day(d) & "/"
If Month(d)<=9 Then
s=s & "0"
End If
s=s & Month(d) & "/" & Year(d)
End If
DisplayDate=s
End Function

Dim sID
Dim iID
Dim oConn
Dim oRs
Dim dDOB

sID = Trim(Request.QueryString.Item("ID"))
iID = GuaranteeCLng(sID, 0)

If iID = 0 Then
'do nothing
Else
Set oRs = oConn.Execute("SELECT history.* FROM history WHERE history.ID = " & iID
If oRs.EOF Then
Else
...
dDOB = CDate(oRs("DOB").Value)
...
Response.Write("Date of Birth: " & DisplayDate(dDOB))
End If
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing
End If
Call DisplayRequest()

##### Share on other sites
Quote:
 Original post by ROBERTREAD1Function GuaranteeCLng(sNum, iDefault) If IsNumeric(sNum) Then GuaranteeCLng = CLng(sNum) Else GuaranteeCLng = iDefault End IfEnd Function'This is a great function for seeing whats going onFunction DisplayRequest()Dim iDim iMax iMax = Request.ServerVariables.Count For i = 1 To iMax Response.Write("")& vbNewLine Next iMax = Request.Form.Count For i = 1 To iMax Response.Write("")& vbNewLine Next iMax = Request.QueryString.Count For i = 1 To iMax Response.Write("")& vbNewLine NextEnd Function'This function shows a date in DD/MM/YYYY formatFunction DisplayDate(d)Dim s If IsDate(d) Then If Day(d)<=9 Then s=s & "0" End If s=s & Day(d) & "/" If Month(d)<=9 Then s=s & "0" End If s=s & Month(d) & "/" & Year(d) End If DisplayDate=sEnd FunctionDim sIDDim iIDDim oConnDim oRsDim dDOBsID = Trim(Request.QueryString.Item("ID"))iID = GuaranteeCLng(sID, 0)If iID = 0 Then'do nothingElse Set oConn = Server.CreateObject("ADODB.Connection") oConn.ConnectionString = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=ASPTest;User ID=ASPTester;Password=PASSWORD;" Set oRs = oConn.Execute("SELECT history.* FROM history WHERE history.ID = " & iID If oRs.EOF Then Else... dDOB = CDate(oRs("DOB").Value)... Response.Write("Date of Birth: " & DisplayDate(dDOB)) End If oRs.Close Set oRs = Nothing oConn.Close Set oConn = NothingEnd IfCall DisplayRequest()

##### Share on other sites
Sander    1332
Quote:

Quoted for truth [smile]

##### Share on other sites
I actually really like ASP.

I don't like ASP.NET.