Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox Problem Please Help! 1

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
I have a foreach statement which is used to echo an array with 3 variables.
Each time a row in the array is echo’d a checkbox is also echo’d.

I want to use this checkbox to allow the users to delete a particular row, so if they want to delete the third row they will check this box an then hit a submit button (which will be called remove) which will reload this page minus the row they have deleted.

What I can’t get my head around is how do I pass a variable from a checkout to my submit (remove) button code.

Hope someone can help.


/***************** Start of foreach statement ************/

foreach ($_SESSION['grind_array'] as $entry)
{
// Get the number of the grind
$grind_number = $entry['counter'];
// Get the array number
$array_number = $grind_number - 1;
echo"<h4>Grind $grind_number</h4>";

// Query to obtain the interest name
$query_result = mysql_query ("SELECT * FROM interests WHERE id_interest = {$entry['Interest']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_interest = $row[1];
echo"<p class = 'confirmation'>Your interest is $confirmation_interest.</p>";
}

// Query to obtain the subject name
$query_result = mysql_query ("SELECT * FROM subjects WHERE id_subject = {$entry['Subject']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_subject = $row[1];
echo"<p class = 'confirmation'>Your subject is $confirmation_subject.</p>";
}

// Query to obtain the level name
$query_result = mysql_query ("SELECT * FROM levels WHERE id_level = {$entry['Level']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_level = $row[1];
echo"<p class = 'confirmation'>Your have choosen $confirmation_level.</p><br>";
}

/**************** Checkbox **********************/
echo'<p class = "confirmation"><input type="checkbox" name="remove" value="$array_number"/>&nbsp;Remove</p>';

}// End of foreach




/****************If remove is clicked***************/
if (isset($_POST['submit']))
{
unset($_SESSION['grind_array'][$array_number]);


ob_end_clean(); // Delete the buffer
header("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/confirmation.php");
exit();
}
 
Can you change:

<input type="checkbox" name="remove" value="$array_number"/>

to

<input type="checkbox" name="remove[]" value="$array_number"/>

and in your $_POST process:

for ($i=0; $i<count($_POST["remove"]); $i++)
{
unset($_SESSION['grind_array'][$_POST["remove"][$i]]);
}

This should remove your selected POST in the Session Array
 
gokeeffe

You still have the same error in your posted script - when you echo out content enclosed in single quotes the variables inside will be treated as literals.
You need to enclose your string in double quotes or concatenate it in the manner I described to you in your last post about this topic.
 
Thank you guys both of your submits helped resolve this problem.

Regards
Graham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top