POST from dynamically generated buttons
Posted: Mon Mar 07, 2011 12:25 pm
Hello!
I am working on a page that queries a DB for image details and displays them with their own dynamically generated Delete button, but I am struggling with handling the POST from the buttons..
The page "works" in so much as the content is generated correctly, but I cant find a way to differentiate between the buttons when POSTing...
the code just loops around the result set, and generates a DIV for each image and button.
What I would like is for the button press to pass the $imageName to the DeleteImage.php form, but because the logic is applied once the page is fully created, the $imageName is always the Last image to be created...
I tried assigning Value of each button to "Button<?php echo $i ?> etc, but it still does the same.. always the last one generated.
And help would be most appreciated!!
I am working on a page that queries a DB for image details and displays them with their own dynamically generated Delete button, but I am struggling with handling the POST from the buttons..
The page "works" in so much as the content is generated correctly, but I cant find a way to differentiate between the buttons when POSTing...
Code: Select all
for ( $i = 0 ; $i < mysql_num_rows($result) ; $i++ )
{
?>
<div id = "middleBox">
<form action="deleteImage.php" method="post" enctype="multipart/form-data">
<br />
<?php
$row = mysql_fetch_assoc($result);
echo '<img src="getImage.php?id=' . $row['id'] . '" alt="' . $row['alt'] . '" title="' . $row['name'] .'"/> ' . "\n";
$imageName = $row['name'];
echo $imageName;
?>
<br />
<input type="hidden" name="imageName" id="imageName" value = "Button"/><br /><br />
<input type="submit" value="Delete image" />
</div>
<?php
What I would like is for the button press to pass the $imageName to the DeleteImage.php form, but because the logic is applied once the page is fully created, the $imageName is always the Last image to be created...
I tried assigning Value of each button to "Button<?php echo $i ?> etc, but it still does the same.. always the last one generated.
And help would be most appreciated!!