SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [resolved]help using arrays in forms

    Hey,

    probs an easy one, my understanding is just a little fuzzy in this area.

    Basically i'm printing out a list of headlines for a news page, each with a checkbox next to them so you can check all the entries you want to delete and click the delete button and it deletes them all.

    I'm just not entirely sure how to send the $_POST values in the form to make an array of id's that my code can interpret and delete.

    in my form I have code generated something like this
    Code:
    <input name=\"checkdelete[]\" type=\"checkbox\" value=\"$id\"/>
    in a while statement, created for each header.

    Then in my delete code i have

    Code:
    $idarray = array();
    if (!isset($_POST['checkdelete'])){
    	$idarray[] = $_GET['id'];
    }else{
    	$idarray[] = $_POST['checkdelete'];
    }
    
    // Delete the news
    for($i=0; $i<count($idarray); $i++){
    	
    	$id = $idarray[$i];
    The $_GET is for the alternative way of deleting single entries that already exists.

    using a tamper I see that the form is sending the multiple POST values for checkdelete, but the PHP doesn't seem to be breaking it apart into an array properly?

    Your help is greatly appreaciated.

    EDIT: I realise now that I was putting the array inside the array. thanks anyway
    Last edited by LetterAfterZ; Aug 16, 2007 at 20:04.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •