Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help with html form & mysql

    So, I have code that will upload a file and place it on the screen, and then I have the form to do so. Now, the problem lies in the fact that after I upload any file to the database, if I refresh the script page, every html element in the form links to that uploaded file.

    Here's the code

    Code:
    <html>
    <img src="/christmastree.png" alt="Your tree!" width="300" height="300" align="absmiddle" />
    <p>
    <p>
    <p>
    <?php
    
    include('login.php');
    
    
    
    
    ?>
    <?php
    
    
    
    $db_select=mysql_select_db($db_database); 
    if (!$db_select) 
    { 
    die ("Impossible Function". mysql_error());
    } 
    
     
    $result = mysql_query("SELECT style, Pictures, Name2 FROM GiftWrap");
    
    if (!$result) 
    {
    die ("Impossible command". mysql_error());
    }
    $j=0;
    
     while ($result_row = mysql_fetch_array(($result)))
    { 
    $j=$j+1;
    
    
      
    echo '<a href="'.$result_row['Pictures'].'"> <img src="' . $result_row['style'] . '" width="250" height="150" alt="******" style="whatever" />';
    echo '<table border=0><tr><td>';
    echo $result_row['Name2'];
    echo '</tr></td></table>'; 
    
    }
    
    mysql_close($connection); 
    
    ?>
    
    </html>
    <html>
    <body>
    
    Welcome to Vgiver. Give a friend a gift!
    
    <form enctype="multipart/form-data" method="post" action="uploadpicture.php">
    
    
    Name of gift recipient (optional):<br>
     <input type="text" name="textline" size="30">
    
    </p>
    <p>
    
    Chooce a gift for your friend!<br>
    
    <input type="file" name="datafile" size="40">
    </p>
    
    
    <input type="radio" name="GiftChoice" value="1">
    
    White & Red Wrapping
    
    <input type="radio" name="GiftChoice" value="2">
    
    
    Gold & Red Wrapping
    
    <input type="radio" name="GiftChoice" value="4">
     
    Red & Green Wrapping
    
    <input type="radio" name="GiftChoice" value="3">
    
    
    Gold & White Wrapping
    
    <input type="radio" name="GiftChoice" value="5">
    
    Double Gold Wrapping
    <table border=0><tr><td>
    <input type="submit" value="Wrap the present!">'
    </td></tr></table>
    
    </form>
    </body>
    </html>
    I am new to this so there are most likely glaring inefficiencies in the code, as well as the obvious omittance of security/validation, but please - this is driving my hair out, only answers pertinent to the specific question will help.

    If you need a reference on what I'm talking about, visit www.vgiver.com.
    Last edited by JamesNebeker; 09-18-2011 at 09:51 AM.

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Anyone?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Are you showing us two separate pages of code there? Or just one page???

    You have
    Code:
    </html>
    <html>
    so I would assume you are talking about two separate pages, but...

    In any case, you say that the action= of your form is "uploadpicture.php" but I don't see where the code for that page is.

    And I don't see how the display of <a...><img...></a> in the loop from the DB is related in any way to the <form> submission.

    Finally, you say "every html element in the form links to that uploaded file." How can that be? Are you saying that even your radio buttons, such as <input type="radio" name="GiftChoice" value="1"> get changed into "links"? Typically, we think of "links" as meaning <a> links, but what do you mean by them?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If you visit www.vgiver.com, which is the site this script is uploaded to, you will see an obvious example of what I mean.

    I mean that the form works perfectly fine, to a point. It uploads records like it is supposed to right up until you upload the first record. After that, the page sets every part of the text to link to the uploaded record. If I'm not making myself clear please just visit www.vgiver.com to see the example, it's extremely obvious once you see it.

    The program is supposed to upload a picture to the database, and set a "wrapping paper" image underneath the tree that you can then click to see the image you uploaded. The program is only supposed to link the gift wrap picture to the uploaded image; however, my code links the entire form to the image. Basically, if you try to use the upload button or any field in the form for that matter, it will take you directly to the page that hosts the record in the database.


    Thanks!
    Last edited by JamesNebeker; 09-18-2011 at 10:55 PM.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Okay, for starters, your HTML code is completely illegal.

    You *do* have only one page.

    And yet you have
    Code:
    <html>
    <img src="/christmastree.png" alt="Your tree!" width="300" height="300" align="absmiddle" />
    <p>
    <p>
    <p>
    <a href="4483123550_238b47925b.jpg"> 
        <img src="http://www.vgiver.com/giftwraps/gift01.jpg" 
             width="250" height="150" alt="[CENSORED!  FOR SHAME!]" style="whatever" />
        <table border=0><tr><td>John Doe</tr></td></table>
    </html>
    <html>
    <body>
    ... and more ...
    So you have your <body> tag *AFTER* your <img> and <a> and </html> tags, just for starters. Illegal HTML.

    But the source of your grief, in any case, is that you have that
    Code:
    <a href="4483123550_238b47925b.jpg">
    *start* tag but *NOWHERE ON THE PAGE* do you have the </a> tag to end it! Again, illegal HTML.

    But the browser *tries* to figure out what you mean. It can't, but it tries.

    So you have converted ALL THE REST OF THE PAGE into one giant link to that 4483123550_238b47925b.jpg image.

    In other words, you need to create basic legal HTML and this has nothing to do with MySQL or uploading images or any of the rest of it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    JamesNebeker (09-18-2011)

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    +1. Thanks


  •  

    Posting Permissions

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