Results 1 to 14 of 14

Thread: Why won't this work? - ASP newbie question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Question

    Ok. This is my first ever ASP thing, and I'm making it with C++, because IIS sounds a bit out of my league.

    Anyway, here's the code:

    Code:
    <HTML>
    <HEAD>
    <TITLE>The St Andrews University Football Website</TITLE>
    </HEAD>
    <BODY>
    
    <!-- Open Players RecordSet->
    <%
    Dim rs, conn, sql, i
    Set rs = Server.CreateObject("ADODB.Recordset")
    Set conn = Server.CreateObject("ADODB.Connection")
    conn = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=http://www.st-and.ac.uk/~www_sem/economics/faculty/mlm/Players.mdb"
    sql = "SELECT * FROM Players"
    rs.Open sql, conn  
    Do
        i = i + 1
        rs.MoveNext
    Loop While Not (rs.EOF)
    rs.MoveFirst
    %>
    
    <!--Tell viewer how many people are playing and when->
    
    <% If i = 0 Then %>
    <H2> There are currently no people signed up to play football on
    <% ElseIf i = 1 Then %>
    <H2> There is currently 1 person signed up to play football on
    <% ElseIf i > 1 Then %>
    <H2> There are currently <% i %> people playing football on
    <% End If
    =rs.Fields(4).Value%>
    </H1>
    
    <P>
    
    <!--Display signup form if more players are needed->
    <font face="tahoma" size=3>
    <% If i > 12 Then %>
    	Sorry, but no more players can be accepted
    <% ElseIf i = 0 Then %>
    	Do you wish to sign up?
    	<br>
    	<hr>
    	<br>
    	Please enter your name here: <input type=Text name="PlayerName" size="20">
    	<br>
    	Please enter your e-mail address here: <input type=Text name="PlayerEmail" size="20">
    	<p>	
    	<input type=submit value="Submit" name="Submit1">
    <% ElseIf i > 0 and i < 13 Then %>
    	Do you wish to sign up if you haven't already?
    	<br>
    	<hr>
    	<br>
    	Please enter your name here: <input type=Text name="PlayerName" size="20">
    	<br>
    	Please enter your e-mail address here: <input type=Text name="PlayerEmail" size="20">
    	<p>	
    	<input type=submit value="Submit" name="Submit1">
    <% End If %>
    
    <!--If somebody is already playing then display their names and e-mail addresses->
    <% If i > 0 Then %>
    Those already playing:
    <Table ALIGN=center>
    	<tr>
    		<th> Name </th>
    		<th> E-mail Address </th>
    	</tr>
    	<% Do Until rs.EOF %> 	
    	<TR>
    		<TD><%= rs.Fields(1).Value & " " & rs.Fields(2).Value %></TD>
    		<TD><%= rs.Fields(3).Value %> </TD>
    	</TR>
    <%	rs.MoveNext
    	Loop 
    Set rs = Nothing
    Set conn = Nothing
    %>
    </BODY>
    </HTML>
    Now when I convert this to VB, it all works hunky dory, but when it's in an ASP script, first of all, my computer said that I could either run it from its current location, or save it to disk (now that's not normal, is it?) and then it tried to open it with InterDev, and then when I put 'View in Browser' for that, it just loaded IE with a blank page.

    The path for the DB is correct, I just want to know what the hell is the problem. Have I missed a '<' out or something.

    Please help, it is kinda urgent.
    Courgettes.

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    It is prompting you to save it to disk because your web server is not processing the ASP page. What web server are you using? you need a real web server (IIS or PWS) in order to do ASP

  3. #3
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    There are a few things in your code that won't work:

    If you are outputting a variable in the middle of HTML such as:
    Code:
    <H2> There are currently <% i %> people playing football on
    
    'it should be like this:
    
    <H2> There are currently <%=i %> people playing football on

    The <%=[variable or expression]%> is shorthand for Response.Write and can only have the variable or expression within the <% %> tags. No other scripting code.

    This:
    Code:
    <H2> There are currently <% i %> people playing football on
    <% End If
    =rs.Fields(4).Value%>
    </H1>
    
    'Should be like this:
    <H2> There are currently <%=i%> people playing football on
    <% End If %>
    <%=rs.Fields(4).Value%>
    </H2>
    This:
    Code:
    <TD><%= rs.Fields(1).Value & " " & rs.Fields(2).Value %></TD>
    
    'Should be like this:
    
    <TD><%Response.Write rs.Fields(1).Value & " " & rs.Fields(2).Value %></TD>
    These problems, however will not cause IIS to not download the page. You have to have an IIS Server set up and the page has to exist in one of it's virtual paths. When you initially set up the solution and project in InterDev, one of the questions the new Project wizard will ask is whether you want to be in Master mode or Local mode. If you are in Local mode, you have to release your working copy to the server in order for the changes to show up. In Master mode, changes are updated to the server copy as they are saved.




    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Also, there's a lot easier way to get the RecordCount instead of looping through the recordset:
    Code:
    Dim rs
    Dim cn
    Dim strSQL
    
    Set rs = Server.CreateObject("ADODB.Recordset")
    Set conn = Server.CreateObject("ADODB.Connection")
    
    cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=http://www.st-and.ac.uk/~www_sem/economics/faculty/mlm/Players.mdb"
    
    strSQL = "SELECT * FROM Players"
    rs.CursorLocation = 3   'adUseClient
    rs.Open strSQL, cn, 3  'adOpenStatic
    
    Response.Write "<H2>There are currently " & rs.RecordCount & " playing football on"
    
    
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing

  5. #5
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    A quick question, when you said
    "I am making it in C++ Because IIS sounds a bit out of my league"

    I dont see any C++ codes in the example you've given, do you mean a seperate application for your database?
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  6. #6
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231

    um, far as .recordcount goes

    RecordCount only works if you are using a Static or KeySet cursor (maybe forwardonly also) since in most language I belive either forwardonly or keyset is automatically chosen as the default cursor, some of the cursors will return a negative one , for the recordcount if it doesnt support recordcount, such cursor is Dyanamic(typically any cursor that can receive update notification when the datasource is updated, cannot have a recordcount).
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Right.

    Thanks for all of the replies, and I'm really grateful to y'all.

    Clunietp:

    Now I spoke with the University's chief IT guy or something and he said that the server runs on Unix, so it doesn't have PWS or IIS.

    Does this mean that I can't use ASP?

    Is there like another way, or should I use like a free server (away from the University) which gives you webspace and supports IIS?

    monte96:

    Thanks, I'll use that.

    Serge:

    I had used that at first, but it always returned -1, so I just used a loop. As you can probably see, there will be a maximum of ... err ... 12 ppl playing, so there won't be a big hit or anything. Maybe there's a reason why it always returned -1?

    EDIT: Ah, that's why, kb244. Thanks.

    kb244:

    To make an ASP in VB you need to do something with IIS, and I just don't understand. When I said C++ I meant that you opened Microsoft Visual C++, and one of the project types is ASP. It wasn't wade with C++, it was made in the C++ program. Sorry if I confused anybody with that.



    [Edited by V(ery) Basic on 09-11-2000 at 02:10 PM]
    Courgettes.

  8. #8
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    Ohhhhh, why dont you just use Visual Interdev, it was made to write ASP, and uses the Frontpage extension to publish to IIS.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  9. #9
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231

    your question about running ASP on Unix

    no you cant run ASP off Unix(they do have ASP plugins for some webservers but they suck) to run ASP, you must have an NT4 Machine with least IIS4, as far as PWS goes, I dont trust it, PWS is only meant for local testing(or learning) and is very unstable and unsecure. you need NT Services to run ASP off a webserver.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Are there any free webspace-providers that support ASP?
    Courgettes.

  11. #11
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    Only very very few that I know of that are horribly limited to what you can do, currently my site (I havent had time to mess with it much) kb244.com is hosted by HostPro, under their NTpro plan which supports any NT technology.

    I'll get information from a friend who does have ASP hosting free , and see if i can figure out the URL (last I heard it supports MySql too, but yer limited to alot)

    reason you wont find many free places for ASP, is because ASP is serverside, so you end up using the provider's CPU usage, and that cost them money, simple HTML documents like on geoshities and what not, only require the browser to download the HTML and interpret it clientside.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  12. #12
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Yes, in order to use Interdev, you must connect to either IIS or a PWS which can be on the local machine. And assuming your running say... Windows95, (the minimum) you can run PWS on the dev. machine to create pages with. I don't know much about it, but Chillisoft makes a product that allows ASP to run on several different Unix web servers.

    as far as recordcount goes, I believe you will need a client side cursor.

    BTW- I just looked at your code again and I don't see where you are even opening the connection before you use it.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  13. #13
    Guest

    Smile

    Concerning the RecordCount, try using the MoveLast function before you use the RecordCount. The reason you get -1 is because the cursor is still standing on the BOF (above the first record). (Someone once told me if you use adOpenKeySet you don't need to use MoveLast. I don't know, haven't tried it yet.) I see you don't specify a Cursor Type in your recordset Open statement, so the default I believe is ForwardOnly.

  14. #14
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Using RecordCount, you don't have to MoveLast, because when you open recordset it always stays on the first record. The only reason why it can be -1 is if you have Server side cursor or your recordset type it something other then adOpenStatic or adOpenKeyset.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width