Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi!
I'm having trouble figuring out why this code won't execute. I've spent a long time trying different syntax variations and ways to get around whatever the issue is, but no luck!
On Page1.php, I query mySQL to list all the rows of a certain table. In the loop that displays rows until there are none left, I have checkboxes put in before each row. At the bottom of the page I have two buttons, an Update and a Delete button. I am only working on Delete right now, and once this works I am sure I can get Update working. After a user selects one or more rows and hits the Delete button I want to display on a new page "Confirm.php" that those rows should be deleted. So I want Confirm.php to display only the rows that the user checked from Page1.php.
The trouble is, I can get the values of the checkboxes from Page1.php to display on Confirm.php only if the checkboxes are static - once I try to use the loop to generate the checkboxes I can't get the chackbox values into the Confirm.php page anymore.
Each row has a unique row_ID key. I was trying to make each checkbox "value" equal to the row_ID of the row being displayed by the loop, and the "name" of the checkbox equal to an array. I thought the checked checkboxes would be passed into the array as the row_ID's of the checked boxes. Then I would be able to loop through the array to find the row_ID's, and requery the database to get the rest of the row information... to then display them.
I think the logic works, but the code is flawed = )
From Page1.php:Code: Select all
//Selects all the rows to display
$result = mysql_query("SELECT * FROM db_data");
// ... some code here to generate part of HTML table
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Prints out a checkbox for each displayed row
echo "<form method='post' action='Confirm.php'>
<input type='checkbox' name='rowstore[]' value='$row[row_ID]'>
</form>";
// ... some code here to generate part of HTML table
echo "
<form action='Confirm.php' method='post'>
<input type='submit' name='Delete' value='Delete' />
<form>
";From Confirm.php:
Code: Select all
// the relevant code from Confirm, checks if Delete button pressed, then:
if($_POST[Delete])
{
if(isset($_POST['rowstore']))
{
$rows = $_POST['rowstore'];
$n = count($rowstore);
$i = 0;
echo "The rows you selected are: " .
while ($i < $n)
{
echo "{
$rowstore[$i]
} ";
$i++;
}
}
}I realize this is not doing everything I want it to, but I am just trying to get it to access the values in the array 'rowstore' right now... after that I should be fine. Any suggestions on why this might not be working correctly? Is it not storing the values of the row_ID in rowstore[], or am I not passing the array correctly or somehow not accessing it correctly? I've tried doing this without isset() also, because I couldn't ever seem to get it working for some reason, but still no go. I've tried variations on these themes, but haven't gotten any of them to work, so this is pretty much my latest try...
Thank you for any help you might be able to lend me!
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]