SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 63
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    help - advanced upload form

    Hello everyone,
    i've been working on a small website as a school project

    I need help with the following things:

    i made a managers login page, managers who logged in can upload images together with a description of the image.
    The uploaded image/desc should then appear on an HTML page on a table (table has 2 rows 1 for the img and 1 for the desc) when ever a new uploaded img/desc added, it should appear on the top of that table.

    The question is how to do that? i've got no clue about uploading and stuff so any help is very appreciated.

    Thanks for the helpers in advance!
    and please no answers like "go google", i've already did that, thanks.

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ulthane

    I like the script provided by Lewis Moten. It is nicely commented for the novice. Have a look at:

    http://www.planet-source-code.com/vb...=8525&lngWId=4
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thank u both for the help
    I've tried Lewis Moten script and it did nicely uploaded.
    But still that doesnt really answer my question.
    i wanna know how to make the uploaded images (and a description) automatically go to a table on 1 of my htm pages. (This table for example: u can see the img on 1 row and the description on the other http://tinypic.com/view.php?pic=2ezsf1y&s=6 )

    Thanks for the support

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Logically you need a database. (MS Access will do here if you're using ASP).

    When you upload the image and description, as well as saving the actual image you should store the image name (or perhaps the full path to the image) and the description text in a database table. While storing you would also assign an ID reference for that entry (an Autonumber would work fine).

    For displaying the details (in reverse order of entry - latest first) then you simply use an SQL query on the database to return a recordset, then loop through the recordset and display the appropriate data.

    Code:
    sSQL = "SELECT * FROM [Table] ORDER BY [ID_Field] DESC"
    http://www5.brinkster.com/hiflyer/db/dbtest.asp might be helpful to get you started.
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that helped
    i've made a db with access and for now i've did it with images only (later ill add desc), now how do i display it on a table like the example i've showed? can any1 give any code example please, and what the page containing the table has to be ? ASP or can it just be HTML page?

  7. #7
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this should help - google the following phrase:

    classic asp database to html table

    you'll get many examples to learn from

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    heh honestly i didnt get that far yet so haven't tried to look for that on google
    going to take a look for it right now and see what ill come up with

  9. #9
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In VERY basic form ...
    Code ASP:
    <%
    sSQL = "SELECT Image,Description FROM ImageTable ORDER BY ImageID DESC"
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "Your connection string"
    Set oRS = oConn.Execute (sSQL)
    If Not oRS.EOF Then
    %>
    <table>
      <tr>
        <th>Image</th><th>Description</th>
      </tr>
    <%
      Do While Not oRS.EOF
        sImage = oRS("Image") 'Let us assume that this is the image file name
        sDesc = oRS("Description")
    %>
      <tr>
        <td><img src="images/<%=sImage%>"></td><td><%=sDesc%></td>
      <tr>
    <%
        oRS.MoveNext
      Loop
    %>
    </table>
    <%
    Else
      Response.Write "<p>No images to display.</p>"
    End If
    Set oRS = Nothing
    oConn.Close
    Set oConn = Nothing
    %>
    Ian Anderson
    www.siteguru.co.uk

  10. #10
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i dont mind if its basic or not , thanks for trying to help
    However, i've tried this form for images only for now and it doesnt show them, it displays a few small squares (in my case 3 squares because i got 3 images stored in the DB for now)
    What to do to solve that?
    Attached Images Attached Images

  11. #11
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ulthane

    Your img paths are incorrect. Those little squares are Firefox's way of telling you that.
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  12. #12
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    how can it be? it knows that i got 3 images by viewing 3 squares, then it means it must know the path to the images isnt it? or if i'm wrong how do i fix it? ill give here some details
    DB name: user list.mdb
    Table name: Files
    rows: fileID (auto number) , filename (image) and some others unnecessary

    And this is how the ASP form looks like

    Code:
    <&#37;
    sSQL = "SELECT FileName FROM files ORDER BY fileID"
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("user list.mdb")
    Set oRS = oConn.Execute (sSQL)
    If Not oRS.EOF Then
    %>
    <table>
    <%
      Do While Not oRS.EOF
        sImage = oRS("FileName")
    %>
      <tr>
        <td><img src="images/<%=sImage%>" /></td>
      </tr>
    <%
        oRS.MoveNext
      Loop
    %>
    </table>
    <%
    Else
      Response.Write "<p>No images to display.</p>"
    End If
    Set oRS = Nothing
    oConn.Close
    Set oConn = Nothing
    %>
    I think that the line marked in red does the problem for me, but still i dont know what exectly to do with it

  13. #13
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ulthane

    Can you confirm:
    • That the images are in the folder,
    • That the images folder is a subfolder of the folder containing the asp page,
    • That the image names have been saved correctly to the db (the same as the actual image name).


    See where that gets you.
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  14. #14
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    lol this is getting very complicated for me ><
    there is no foldier at all containing images
    all images are stored in the database...
    i want to view them straight from the DB
    i got that DB from some guide some1 linked here, how do i just view images from the DB? i see to view something from the DB this guide uses the following line:
    Code:
    <A href="Database_Download.asp?FileID=<%=FileID%>"><%=FileName%></A>
    So i belive i need something that will go for each FileID in the table and view the image it contains instead of the line i got now marked in red, how to do that?

  15. #15
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    haha finally, i got it working
    Thanks to all of u for the help, im going to add the desc fields now with hope of no probs with it

  16. #16
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You created an ASP page that read the image data from the database (based on the FileID), set the content-type header and streamed the image to the browser?

    Code:
    <img src="getimg.asp?id=1" />
    Ian Anderson
    www.siteguru.co.uk

  17. #17
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    yeh something like that
    i've changed that line to this:
    Code:
     <td><img width="280" height="370" src="Database_Download.asp?FileID=<%=sImage%>" /></td>
    Toghether with some other files from Lewis Moten's guide
    However i need help with another thing, some1 mentioned viewing images in reverse before, how to do that ?
    I mean i want to view the images in reverse order (example 3 > 2 > 1 and not 1 > 2 > 3)

  18. #18
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh nvm, i see it already appears at a reversed order , now also added desc field and it works perfect! thank u all

    Now i wanna work on another thing, those tables im talking about are 3 tables, 1st table contains Dogs for adoption, 2nd Cats for adoption and 3rd Adopted pets, i want to make a form, so if for example a dog got adopted i can take his pic and desc and Move them to the Adopted table, how to do that ?

  19. #19
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're really now into the realms of needing to have a clear database structure definition - understanding what tables are needed and how they relate to each other. For example ...

    Table: AnimalTypes
    TypeID | AnimalType (e.g. 1 | Dog, 2 | Cat)

    Table: AdoptionStatus
    AdoptID | AdoptText (e.g. 1 | Available, 2 | Adopted)

    Table: Animals
    ID | TypeID | Photo | AnimalName | Description | AdoptID (e.g. 1 | 1 | [image data] | Fido | A border collie | 1) ... means a dog called Fido that is a border collie and is Available for adoption

    You could select all Dogs available for adoption via the SQL command ...

    SELECT * FROM Animals WHERE TypeID=1 AND AdoptID=1 ORDER BY ID DESC

    You could select all Cats available for adoption via the SQL command ...

    SELECT * FROM Animals WHERE TypeID=2 AND AdoptID=1 ORDER BY ID DESC

    You could select all Animals that have been adopted via the SQL command ...

    SELECT * FROM Animals WHERE AdoptID=2 ORDER BY ID DESC

    As you can see, a decent database design makes retrieving the information much easier. (And my example isn't really a decent design, but is good enough for an example. I suggest searching for DATABASE NORMALIZATION for more info on this subject).
    Ian Anderson
    www.siteguru.co.uk

  20. #20
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    wow that little thing became complicated to bits
    Anyways i understood what u meant, i do wanna go for it, but now im really lost, i dont have any idea where i should begin from..any advices =)? and if im logged in as a manager, how would i be able to edit that dog ID 2 for example been adopted and needs to be moved to the adopted page?

    no words piece of project, but worth it Thanks for ur help!

    ****
    Edit*
    Got the tables rdy
    Lets start from the very beginning, what should i have in my Upload form? (since now i have to send info to 3 different tables, i've really got no idea how to begin this)

  21. #21
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ok so i've made the uploading form
    I've made that table Called animals, i didnt create the others because i figured out it has no use? (tell me if im wrong, since the Animals table contains animaltype / adoptionstatus anyways...)
    Now, im trying to make the ASP form to display dogs only on the dogs page like u adviced, and i keep getting an annoying error ><
    This is the form:
    Code:
    <&#37;
    sSQL = "SELECT fileID,Desc FROM Animals WHERE adoptionstatus=1 AND animaltype=1 ORDER BY fileID DESC"
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("user list.mdb")
    Set oRS = oConn.Execute (sSQL) ' Line 45
    If Not oRS.EOF Then
    %>
    <table align="center" style="width: 570px;margin-bottom:10px;" border="5"  >
    <%
      Do While Not oRS.EOF
        sImage = oRS("FileID")
        sDesc = oRS("Desc")
    %>
      <tr>
        <td valign="middle" align="center"><a href="Database_Download.asp?FileID=<%=sImage%>"<img border="0" width="290" height="370" src="Database_Download.asp?FileID=<%=sImage%>" /></a></td><td align="right"><%=sDesc%></td>
      </tr>
    <%
        oRS.MoveNext
      Loop
    %>
    </table>
    <%
    Else
      Response.Write "<p>No images to display.</p>"
    End If
    Set oRS = Nothing
    oConn.Close
    Set oConn = Nothing
    %>
    This is the error
    Code:
    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    /S.O.S Pets - Website/1dogs1.asp, line 45
    Thanks for the support
    hehe nvm, again, i've solved it :P the first line should've looked like this:
    Code:
    sSQL = "SELECT * FROM Animals WHERE (adoptionstatus= '1')  AND (animaltype= '1')  ORDER BY fileID DESC"
    So now i've got all the tables working, how do i start the form to move an animal from the dogs / cats tables to the adopted one?

  22. #22
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Easiest way is to have an admin page which lists all the animals awaiting adoption, and against each one have a checkbox whose value is the fileID. When you submit the form you capture the fileID values then run an SQL query to simply update the Animals table to set the adoptionstatus to 2.

    e.g. get all the IDs and group them as a comma-delimited string of values (e.g. IDs = "1,3,4"). Then you could run a query such as below:

    sSQL = "UPDATE Animals SET adoptionstatus='2' WHERE fileID IN (" & IDs & ")"

    BTW - the reason for the additional tables is to allow expansion, and more efficient usage. For example, the AnimalTypes table allows you to add more animal types, but also allows you to have a textual description of the animal types whilst keeping the main Animals table streamlined (by it containing ID values rather than the textual definition of those ID values).

    Like I said earlier - read up on database normalization and things should become clearer.
    Ian Anderson
    www.siteguru.co.uk

  23. #23
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    heh thanks, i will try that once ill finish with the upload stuff still getting a few problems but i think i can handle
    Just 1 thing, how do i increase the amount of letters the text field can get? for some reason i think it cant gather more then 5 words or so :/

  24. #24
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    The topic is straying away from the original question, but I agree with siteguru.

    I used to make 1 table with all kinds of fields. They "worked" and as long as my apps remained simple it was fine. But once things got more complex the "one big table with everything" approach became a nightmare.

    So if you have any reason to think this may need to scale well, it's better to plan ahead than it is to try and patch things up later after it gets out of control.

    But if you are more than 100% certain that the requirements won't change (or if this is only a practice app for learning purposes) then I guess you could go with it as it is.

  25. #25
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well yes thats just for learning purposes for now
    i dont think there'll be need for me to seperate the tables, since it wont get much complicated, the only things i've left is the "move_pet" and "pet_delete" pages and its done

    Still, i need help on how to increase the length the desc field can get, its way too short...


Bookmarks

Posting Permissions

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