...

View Full Version : Help with html form & mysql



JamesNebeker
09-18-2011, 04:35 AM
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


<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.

JamesNebeker
09-18-2011, 09:28 PM
Anyone?

Old Pedant
09-18-2011, 10:42 PM
Are you showing us two separate pages of code there? Or just one page???

You have

</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?

JamesNebeker
09-18-2011, 10:51 PM
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!

Old Pedant
09-18-2011, 11:27 PM
Okay, for starters, your HTML code is completely illegal.

You *do* have only one page.

And yet you have


<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

<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.

JamesNebeker
09-18-2011, 11:43 PM
+1. Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum