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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.