Jump to content

[SOLVED] Problem with more than one form on a page?


Michdd

Recommended Posts

I created something that allows users to upload images then it stores all information from the form (file name, url, comment, name, and password) Then it gets this information from the database and lists the files in an organized way. On each of those entries when it's generated it has a form to allows users to delete their images with the password they used to upload it. I also set a password that will always work (for administrators) Now when I only have 1 image generated on the page it works fine, I can delete the images, however, if I have 2 entries on the page, and I try to delete the most recent one, then there's a problem and it just gives me my message that is supposed to be generated when an incorrect password was entered.

 

Could this be some kind of problem because there's more than form on the page?

There's a lot of code, because it's the whole thing I created. It's not the most professional, but I'm still producing it. So don't bother me about that:

 

Note: There are only the parts of the code that pertain to this problem:

 

   while($row = mysql_fetch_array( $result )) {

$div++;
$geturl = $row['url'];
$name = $row['name'];
$getcomment = $row['comment'];
$getid = $row['id'];
$getpass = $row['password'];
$size = getimagesize($geturl);
$linktoimage = str_replace('http://theforbiddengates.net/project/r/images/', '', $geturl);
$getfilesize = 'images/'.$linktoimage;
list($width, $height) = $size;
$imagesize = filesize($getfilesize);
$orsize = getimagesize($geturl);
list($orwidth, $orheight) = $orsize;
$type = "B";

if($imagesize > "1000") {

$imagesize = $imagesize / "1000";
$type = "KB";

}

if($imagesize > "1000") {

$imagesize = $imagesize / "1000";
$type = "M";

}

if($width > "250") {
$width = "250";
}
if($height > "250") {
$height = "250";
}

if($getcomment == "") {

$getcomment = "No comment";

}



echo "<table min-width='553px'>
<tr valign=\"top\"><td>";
echo "<a href='$geturl'>$linktoimage</a>";
echo ' ('. $imagesize . $type;
echo ' '.$orwidth.' X '.$orheight.')';
echo "<br />";
echo "<a name=\"".$getid."\"></a>";
echo "<a href=\"".$geturl."\">";
echo "<img src=\"".$geturl."\" width=\"".$width."\" hieght=\"".$hieght."\" >";
echo "</a>";
echo "<br /> <center>[Click to Enlarge]</center>";

echo "</td><td>";
echo "Posted by <font color='800517'><b><u>$name</u></b></font> | ";
echo "Image id: #";
echo $getid;
echo "<div id=\"".$div."\">

	<form action=\"delete.php\" method=\"post\">
	Password: <input type=\"password\" name=\"password\" />
	<input type=\"hidden\" name=\"id\" value=\"".$getid."\" />
	<input type=\"submit\" value=\"Delete\" />
</div>";


echo "<input type=\"button\" onclick=\"$('$div').slide('').hide()\" value=\"Hide/Show\">";
echo "<hr />";
echo "<p>";
echo $getcomment;
echo "</p>";
echo "</td></tr>";
echo "</table>";




}

 

There's a lot of stuff in there just thrown together. That generates all the information from the database after being put in by this form:

 

<form action="index.php" method="post" enctype="multipart/form-data">
   <p><table border="0">
      <tr><td align="left"><label for="file">Select a file:</td></label> <td><input type="file" name="userfile" id="file"></td></tr> <br />
  <tr><td>Name <br /><font size="1">(optional)</font></td><td><input type="text" name="name" />
  <tr><td>Password <br /><font size="1">(optional)</font></td><td><input type="password" name="password" />(Used for deleting images)</td></tr>
  <tr><td>Comment <br /><font size="1">(optional)</font></td><td><input type="text" name="comment" />
  <input type="hidden" name="section" value="r" />
  <input type="hidden" name="auth" value="1" />
      <tr><td colspan="2"><center><button>Upload File</button><input type="Reset" name="resetbtn" value="Reset"></center></td></tr>
  <center></table>

 

The file used to delete images from the database (form comes from the first segment of code:

 

<?php

include('connect.php');

$entered = $_POST['password'];
$id = $_POST['id'];

if($id != "") {

$Find = mysql_query("SELECT * FROM images WHERE id='$id'");

if(!mysql_num_rows($Find)) {

echo "No image with that ID exists";

}

$result = mysql_query("SELECT * FROM images
WHERE id='$id'") or die(mysql_error());  

$row = mysql_fetch_array( $result );

$password = $row['password'];

if($entered == "example") {
$result = mysql_query("SELECT * FROM images
WHERE id='$id'") or die(mysql_error()); 
while($row = mysql_fetch_array( $result )) { 
$geturl = $row['url'];
}
$linktoimage = str_replace('http://theforbiddengates.net/project/r/images/', '', $geturl);
mysql_query("DELETE FROM images WHERE id='$id'") 
or die(mysql_error());  

echo "The image was deleted from the database. You will now be redirected!";

$myFile = 'images/'.$linktoimage;
unlink($myFile);

header('Location: http://www.theforbiddengates.net/project/r/');
} 


if($entered == "example") {
$result = mysql_query("SELECT * FROM images
WHERE id='$id'") or die(mysql_error()); 
while($row = mysql_fetch_array( $result )) { 
$geturl = $row['url'];
}
$linktoimage = str_replace('http://theforbiddengates.net/project/r/images/', '', $geturl);
mysql_query("DELETE FROM images WHERE id='$id'") 
or die(mysql_error());  

echo "The image was deleted from the database. You will now be redirected!";

$myFile = 'images/'.$linktoimage;
unlink($myFile);

header('Location: http://www.theforbiddengates.net/project/r/');
} 
else {
echo "wrong Password";
}

if($password == "") {

echo "When uploaded, this image was specified no password, because of this it can not be deleted<br />";
die();
}
if($entered == $password) {
$result = mysql_query("SELECT * FROM images
WHERE id='$id'") or die(mysql_error()); 
while($row = mysql_fetch_array( $result )) { 
$geturl = $row['url'];
}
$linktoimage = str_replace('http://theforbiddengates.net/project/r/images/', '', $geturl);
mysql_query("DELETE FROM images WHERE id='$id'") 
or die(mysql_error());  

echo "The image was deleted from the database. You will now be redirected!";

$myFile = 'images/'.$linktoimage;
unlink($myFile);

header('Location: http://www.theforbiddengates.net/project/r/');

} else {

echo "Wrong Password";
}



} else { 

echo "No image id was specified";

} 



?>

 

This site is here:

 

http://theforbiddengates.net/project/r/

 

That's just a place I'm using to test it, and get everything working.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.