Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP Problem...

Options
  • 03-11-2005 7:23pm
    #1
    Registered Users Posts: 1,488 ✭✭✭


    I am trying to set up a website thru asp. I want to put a photos page on it. I have the photos under different categorys in a database and the initial photos page just lists the categories. I want to make the page the category name links to display the first photo in the group and a next and previous button below it to navigate the photos in the category.

    I tried the following code but its full of errors. Is there an easier way or how should the code be written.

    Thanks in advance for the help :confused:
    <%@LANGUAGE=&quot;VBSCRIPT" CODEPAGE="1252"%>
    <%option explicit%>

    <%function photo
    'declare variables
    dim oCn, oRS, strSQL, piccode, id, thegroup, back, forward

    thegroup = request.querystring("group")
    strSQL = "SELECT * FROM photo WHERE group='" & thegroup & "'"
    set oCN = server.createobject("ADODB.Connection")
    oCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & Server.Mappath("db/homepg.mdb")
    set oRS= oCn.execute( strSQL )
    back = oRS.moveprevious
    forward = oRS.movenext
    'error checking
    if err.number = 0 then
    'check to see if recordset is empty
    if oRS.EOF and oRS.BOF then
    response.write "Nothing happening at the moment!!"
    else
    'loop here
    do while not oRS.EOF
    response.write "<a class='largephoto' href='photos/" & oRS("photo") & ".jpg'> <img src='" & oRS("photo") & ".jpg'></a>"

    response.write "<br><a class='photodetail' href='photos/" & oRS("photo") & ".jpg'>" & oRS("details") & "</a>"
    response.write "<br><img src='images/back.gif' onmousedown='"& back &"'><img src='images/spacer.gif'><img src='images/forward.gif' onmousedown='" & forward & "'>"
    loop
    end if
    else
    response.write "<br/>Thechnical problem!<br/>I'm looking in to it!"
    end if
    oRS.close
    oCn.close
    set oRS=nothing
    set oCn=nothing

    end function


    %>


Comments

  • Closed Accounts Posts: 132 ✭✭canker


    Does the page run at all / what errors are you getting?


  • Registered Users Posts: 1,488 ✭✭✭mathew


    Im getting errors from the following lines so far. There could be more. If there are any blindingly obvious ones I'd appreciate them being pointed out!!!! ;)
    strSQL = "SELECT * FROM photo WHERE group='" & thegroup & "'"
    - Syntax errors (I think the syntax is right now tho!)

    back = oRS.moveprevious
    - operation cannot be used in this context
    forward = oRS.movenext
    - operation cannot be used in this context
    response.write "<a class='largephoto' href='photos/" & oRS("photo") & ".jpg'> <img src='" & oRS("photo") & ".jpg'></a>"
    - *something* or ordinal cannot be found in the collection (cant remember what the something is!)
    response.write "<br><a class='photodetail' href='photos/" & oRS("photo") & ".jpg'>" & oRS("details") & "</a>"
    - *something* or ordinal cannot be found in the collection (cant remember what the something is!)
    response.write "<br><img src='images/back.gif' onmousedown='"& back &"'><img src='images/spacer.gif'><img src='images/forward.gif' onmousedown='" & forward & "'>"
    - Operation cannot be used in this context

    These aren't exact quotes of the errors because i cant remember them word for word but its the rough wording

    Thanks


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    forward = oRS.movenext
    back = oRS.moveprevious
    

    oRS.movenext/moveprevious moves the recordset position to the next or previous record. It doesn't return a value so you can't popluate a variable with it.

    Same goes for the following code snippet as back and forward haven't been populated.
    response.write "<br><img src='images/back.gif' onmousedown='"& back &"'><img src='images/spacer.gif'><img src='images/forward.gif' onmousedown='" & forward & "'>"
    

    To populate the variables you'll need to do is something like
    oRS.MoveNext
    forward = oRS("photo").value
    

    How your going to fit this into your code is upto you :)

    *something* or ordinal cannot be found in the collection

    What are the field names being returned in the recordset? My ado is a bit out of date but it sounds like the photo field isn't present.


  • Registered Users Posts: 2,781 ✭✭✭amen


    first off having no order by clause in your sql is a bad idea makes it hard to page the results

    is I was doing this I would have a unique id for each photo and store this as you move forward/backwords and use this for selecting the data

    I would either store the full path in the db or the image and extract it back
    let us know how u get on


  • Moderators, Politics Moderators Posts: 39,788 Mod ✭✭✭✭Seth Brundle


    have a look at some of the paging examples here... and incorporate one into your basic code* once that works.

    * basic code being where you see your single picture but omit the code to generate your next and previous links


  • Advertisement
  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    I have ranted about SQL injection here so many times that I have summarised it here: http://blog.synnottsoftware.com/ranty-ranty-rob/sql-injection-rant/

    It really, really is a bad idea to write webby stuff without having some knowledge of the risk you're courting.


  • Registered Users Posts: 1,656 ✭✭✭rogue-entity


    Why dont you just use PHP, it works a lot better with SQL and it is a lot easier to code then ASP. IMO ASP is rubbish.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Why dont you just use PHP, it works a lot better with SQL and it is a lot easier to code then ASP. IMO ASP is rubbish.

    Employers, college assignments, available technology, available skills on the ground. There's loads of reason why somebody has to work with one technology instead of an other.


  • Registered Users Posts: 250 ✭✭ikoonman


    I think this is what you want. (There are better ways of doing this)

    Create a DNS entry that points to your Access MDB
    dim objDb, objRs
    
    strGroup = request("group")
    
    strSql = "SELECT * FROM photo WHERE group='" & strGroup & "';"
    
    set objDb = server.createobject("ADODB.Connection")
    objDb.open "DSN=mydbdns"
    
    set objRs = objDb.Execute(strSql)
    
    if objRs.Eof then
      response.write("No records")
    else
      while not objRs.Eof
    	response.write "<a class='largephoto' href='photos/" & objRS("photo") & ".jpg'> <img src='" & objRs("photo") & ".jpg'></a>"
    	response.write "<br><a class='photodetail' href='photos/" & objRs("photo") & ".jpg'>" & objRs("details") & "</a>"
    	objRs.Movenext
      loop
    end if
    
    objRs.close
    objDb.close
    


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    You're doing it again, group is an sql keyword. Those who fail to learn the lessons of history are destined to repeat them ;)
    If you don't want to rename the column then refer to it as table.column in your sql so the sql parser can understand your statement, i.e. in this case 'photo.group' instead of just 'group' which the parser assumes is for a 'group by' summary.

    Beware of copying and modifying existing code without understanding it. It's not just the lack of learning and missing out on the joy of real productive power, it's the false sense of security. If you implement this after others have corrected the code can you maintain it when it breaks or gets hacked?

    If the problem you're having is lack of references here are some links that might help:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbscripttoc.asp
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acfundsql.asp
    http://www.askasp.com/main.asp

    If you're experiencing time pressure in general check out http://ianrpubs.unl.edu/homemgt/nf172.htm

    Others may post better links, and google is always handy to find threads discussing a particular error message. Break down the problems and solve them one by one. It's also a good idea to keep a log of problems and solutions for future reference.

    I'd also echo (php pun intended) what rogue-entity said, if you are setting out to be a web systems developer I'd strongly recommend switching to AMP (apache/mysql/php). I used to develop asp/iis/access/nt systems, but any time I wanted to move up the food chain I ran into pricey licences and boss refusal. Worse, MS strive to channel developers into supporting MS cash cows and this takes priority over providing the freedom to develop the best system, that's one of the reasons powerful community alternatives are exploding in popularity.

    If you are interested in exploring that route here are a few top links that represent the keys to the kingdom:
    PHP Download
    PHP Starter Tutorial
    PHP Tutorials
    PHP Official Manual

    PHP/Mysql Tutorial

    MySql download
    MySql Tutorials
    MySql Official Manual
    MySql Administrator Program
    MySql Query Browser

    Apache Web Server download
    Apache Web Server Tutorial
    Apache Web Server Official Manual

    You can install and run these on a windows PC for free, and down the line you can swap over to Linux, but for the moment the above are enough to get you on the road to becoming a capable and prosperous AMP developer.


  • Advertisement
  • Registered Users Posts: 250 ✭✭ikoonman


    It was late, i wanted to do a quick response, trying to get the guy on his way. Waffling on about egos, instead of trying to solve the problem, does not really help.

    For those who actually read this thread to solve the problem: If you really want to use the word GROUP, enclose it in square brackets ([]):
    strSql = "SELECT * FROM photo WHERE [group]='" & strGroup & "';"
    


  • Moderators, Politics Moderators Posts: 39,788 Mod ✭✭✭✭Seth Brundle


    ikoonman wrote:
    For those who actually read this thread to solve the problem: If you really want to use the word GROUP, enclose it in square brackets ([]):
    Wouldn't it be easier to avoid using keywords as names? :rolleyes:


  • Registered Users Posts: 250 ✭✭ikoonman


    kbannon wrote:
    Wouldn't it be easier to avoid using keywords as names? :rolleyes:

    Sure it will, for experienced developers, but for someone who started up a little project who does not neccesarily want to get tangled up in tutorials etc this should suffice. Once up and running, he may never actually do anything to the site again. If he does, he may have more time to learn and use correct sql syntax.

    IMHO, Going on about switching over to PHP is really just discouraging people starting up and not really helping them solve the problem, unless they are *actually* looking for the correct software/dev tools to do this in.


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    ikoonman wrote:
    IMHO, Going on about switching over to PHP is really just discouraging people starting up and not really helping them solve the problem, unless they are *actually* looking for the correct software/dev tools to do this in.
    You gave good help and that is laudible.

    My post addressed not just the present sql keyword problem, but also some links to help with coding in general on his current platform, and finally the long term alternative development platform issue.

    It's a bit like helping an apprentice mechanic with a broken down car by pointing out a loose spark-plug lead, advising of some good manuals for that car, and also why you believe another marque is more reliable and some good manuals for that one.

    I don't think it's an unfair imposition to offer free advice when giving free help, and why keep something that could be hugely beneficial in the future a secret?


Advertisement