Jump to content

Deleting multiple variables, but i can send one from the forum.


Rommeo

Recommended Posts

Hi

i m new at php programming and i have a problem about sending multiple variables and deleting them.

My question is ;

 

i have created a page(listpages.php) that's output s like ;

//<form action='deletepages.php' method='post' >
Page($page)  -   Number($id) - Delete ?
    contact                  1         *checkbox*(named as mycheckbox,value=$page)
    about                     2         *checkbox*(named as mycheckbox,value=$page)
    photos                    3         *checkbox*(named as mycheckbox,value=$page)
*Submit Button*
//</form>

 

and my deletepages.php is ;

.
.
$page = $_POST['mycheckbox'];

$sql=mysql_query("DELETE FROM tbl_pages WHERE page='$page'") || die ( mysql_error() );

echo "That's OK<br/>";

My problem is, I can only send one variable from "listpages.php" to "deletepages.php" So I should only check one box and confirm it,then it deletes the page. When I select multiple checkboxes(pages), it only deletes the last one I checked.. I want to delete multiple pages like I can choose more than one pages and I can delete it for the one time. Is it possible ? I ll be glad if anyone can help ..

 

Thanx in Advance.

you need to name your check boxes like an array.

<input name="fave[A]" type="checkbox" value="true">
<input name="fave[b]" type="checkbox" value="true">
<input name="fave[C]" type="checkbox" value="true">

 

for the POST you should use a foreach to read through each submitted value

if(isset($_POST['fave'])) {
foreach($_POST['fave'] as $id=>$value) {
	echo $id."<br/>";
}
}

 

if i checked box A and box C then i would get the output

A = true
B = true

 

where A is the index array and true is the value of the checkbox (in your case, $page)

 

 

 

hope this helps. let me know if i misunderstood your question or need more help :)

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.