Opening a file from a databse using a form

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Opening a file from a databse using a form

    Forgive me if this is simple but I am stumped. I created a MYSQL database that
    contains our newsletters in pdf. On our main page I want to create a jump menu
    that allows visitors to choose the newsletter they want to view. I populated
    the menu dynamically with the content field from the recordset (the one that
    contains the PDF files). Now I am not sure what to place in the action window
    of the form. I assume it must be a php file of some sort. Being that is the
    case what code do I need in this php file to force the browser to open the
    selected pdf file? Thanks.

    Darren

    Hung Kuen Kung Fu Guest

  2. Similar Questions and Discussions

    1. Supspend opening the file after create pdf file from Adobe PDF
      Every time I create pdf file, the file opens automatically upon completion. I am using v6.01 Pro. Please advise how to suspend the opening the...
    2. Data transfer from SQL Server 2000 databse to DB2 databse
      SQL Server 2000 database table-data should be transfered to DB2 databse tables. The table formats are same in the two databses. If you have any...
    3. opening asp file and loading certain text into a form
      Hello. Can anyone help me with the following. I have a config.asp file with contains information like: ...
    4. Bitmaps are displaced when opening FH9 file-I need a test file
      Would someone who has reported opening FH 9/10 files in FH MX containing bitmaps that were being displaced please send me a file that displays this...
    5. Opening a form
      I have a table of 260 customers with 30 fields in each record. After building a query based upon that table's relationship with three other tables,...
  3. #2

    Default Re: Opening a file from a databse using a form

    Is this just not possible?

    Darren
    Hung Kuen Kung Fu Guest

  4. #3

    Default Re: Opening a file from a databse using a form

    .oO(Hung Kuen Kung Fu)
    >Forgive me if this is simple but I am stumped. I created a MYSQL database that
    >contains our newsletters in pdf.
    The files are stored in the DB? Why not use plain files and just store
    the filenames in the DB?
    >On our main page I want to create a jump menu
    >that allows visitors to choose the newsletter they want to view. I populated
    >the menu dynamically with the content field from the recordset (the one that
    >contains the PDF files). Now I am not sure what to place in the action window
    >of the form. I assume it must be a php file of some sort.
    Yep. It has to be a script that gets the name of the requested
    newsletter from the submitted form data, fetches the file from the DB
    and returns it with correct headers to the browser.
    >Being that is the
    >case what code do I need in this php file to force the browser to open the
    >selected pdf file?
    Don't try to force anything. Just deliver the file as if it would have
    been requested directly and delivered by the server. Use the header()
    function to return the correct content type (application/pdf) and the
    filename. Then send the file content. Check the header() documentation
    for an example code.

    [url]http://www.php.net/header[/url]

    Micha
    Michael Fesser Guest

  5. #4

    Default Re: Opening a file from a databse using a form

    I checked out the header information but I am not sure what I am missing.
    Plus, for some unknown reason, my menu that I bound the db info too no longer
    lists the files. I didn't change anything just didn't know what to add to
    complete. Is there anywhere I can look at some code that does a similar
    function. I assume I can get the form to send the chosen id to the php page.
    Again, just don't know what the heck to put on that php page. Thanks.

    Darren

    Hung Kuen Kung Fu Guest

  6. #5

    Default Re: Opening a file from a databse using a form

    .oO(Hung Kuen Kung Fu)
    >I checked out the header information but I am not sure what I am missing.
    >Plus, for some unknown reason, my menu that I bound the db info too no longer
    >lists the files. I didn't change anything just didn't know what to add to
    >complete.
    Can you post an URL and some of the code you already have?
    >I assume I can get the form to send the chosen id to the php page.
    Yep, it's plain HTML.
    >Again, just don't know what the heck to put on that php page.
    Assuming the form is sent using the GET method you'll find the ID of the
    selected newsletter in the $_GET array. Check if a newsletter with this
    ID exists in the database, get its content and send it back to the
    client.

    Micha
    Michael Fesser Guest

  7. #6

    Default Re: Opening a file from a databse using a form

    I am not experienced enough in hand php coding to put this all together. My
    hand coding is limited. I can understand it when I see it and can tweak
    another example to what I want but I don't have enough knowledge to do it from
    scratch. Most of the dynaic PHP stuff i do I use Dreamweaver's capabilities to
    do for me. I assume what I was trying to do was simple but I don't even know
    where to start. I will simply have to figure out another wat to draw the
    files back out of the database. It sucks being retarded (ha ha). Thanks for
    the help. I will post what I have so far. So, if you want check back a bit
    later.

    Darren

    Hung Kuen Kung Fu Guest

  8. #7

    Default Re: Opening a file from a databse using a form

    OK,

    Here is the code for my search page. Like I said, it once worked but now it
    won't even list the files. I chose the content field for both the name and the
    value when I was creating the dynamic binding of the menu in the form. I have
    absolutely no clue what to put in my results.php page though I did set the
    parameters of the link to attach the id filed of the recordset.


    Thanks

    Darren


    <?php require_once('Connections/mlgolf.php'); ?>
    <?php
    mysql_select_db($database_mlgolf, $mlgolf);
    $query_rsnewsletters = "SELECT * FROM upload";
    $rsnewsletters = mysql_query($query_rsnewsletters, $mlgolf) or
    die(mysql_error());
    $row_rsnewsletters = mysql_fetch_assoc($rsnewsletters);
    $totalRows_rsnewsletters = mysql_num_rows($rsnewsletters);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <form name="form1" method="post" action="results.php?id=<?php echo
    $row_rsnewsletters['id']; ?>">
    <select name="select">
    <?php
    do {
    ?>
    <option value="<?php echo $row_rsnewsletters['content']?>"><?php echo
    $row_rsnewsletters['content']?></option>
    <?php
    } while ($row_rsnewsletters = mysql_fetch_assoc($rsnewsletters));
    $rows = mysql_num_rows($rsnewsletters);
    if($rows > 0) {
    mysql_data_seek($rsnewsletters, 0);
    $row_rsnewsletters = mysql_fetch_assoc($rsnewsletters);
    }
    ?>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>
    <?php
    mysql_free_result($rsnewsletters);
    ?>

    Hung Kuen Kung Fu Guest

  9. #8

    Default Re: Opening a file from a databse using a form

    .oO(Hung Kuen Kung Fu)
    >I am not experienced enough in hand php coding to put this all together. My
    >hand coding is limited.
    OK.
    >I can understand it when I see it and can tweak
    >another example to what I want but I don't have enough knowledge to do it from
    >scratch. Most of the dynaic PHP stuff i do I use Dreamweaver's capabilities to
    >do for me.
    And I always use my own scripts ...
    >I assume what I was trying to do was simple but I don't even know
    >where to start.
    It is quite simple. Maybe I can setup a little example page tomorrow.

    The only little problem is that the files are stored in the database. In
    most cases that's not the best solution for some reasons (performance
    etc.) Any chance to change that back to regular files? With plain files
    it would be even simpler to let the user download one: You just have to
    link to it and don't need any script.

    Micha
    Michael Fesser Guest

  10. #9

    Default Re: Opening a file from a databse using a form

    Well The upload scrpt I used uploads the pdf files to a mysql database. The
    reason I di it this way is the folks that are going to be maintaining the site
    know very little about web pages and I needed it to be automated in a sense.
    That is why I wanted to use the form to dynamically select the choices from the
    database so I would not have to manually add new links to the form pull-down
    menu. The form doesn't seem to work anymore anyway. Check out my test page
    here. I don't know what its doing now!
    [url]http://www.meadowlakegolfclub.ca/indexfake.php[/url]

    I have the form send the content id through a url to results.php. This is the
    only code I put on the results page.

    <?php

    header('Content-type: application/pdf');

    $content = $_GET['content'];

    ?>

    I am sure I am missing somthing because I am not sure what I need to begin
    with. Thanks for the continued help. It is really appreciated.

    Darren

    Hung Kuen Kung Fu Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139