Rommeo Posted June 21, 2008 Share Posted June 21, 2008 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. Quote Link to comment Share on other sites More sharing options...
Mattyspatty Posted June 21, 2008 Share Posted June 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 No, don't do it like that. Just name them ALL as mycheckbox[] (nothing in the []), and then $_POST['mycheckbox'] will be a numerically indexed array that you can sort through with foreach. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.