Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    update db on checkboxes

    Now that I've got my form populating, I'm trying to get it to update the database.

    It's a series of checkboxes with the name 'option2' but different values. For those that are checked, I want to add an entry to the database. For those that are unchecked I want to delete an entry from the database if it exists.

    Here's what I'm trying right now, but I must have a syntax error? I'm getting "Invalid argument supplied for foreach() "

    PHP Code:
    $id 24;
    foreach(
    $_POST['option2'] as $row) {
    $list2 implode(','$row);
    $sql2a "DELETE FROM plant_edible_link WHERE plant_id = $id and edible_id NOT IN ($list2)";
    $sql2b "INSERT INTO plant_edible_link(plant_id, edible_id) VALUES ($list2)";


  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    a little progress in understanding implode/explode

    I can see my results. but now I'm trying to figure out how to turn it into an insert or delete query action...

    PHP Code:
    $imploder=implode(','$_POST['option2']); 
    //echo $imploder."<br>";
    $exploder explode(','$imploder);

    //print_r($exploder);

    foreach($exploder){
    //$add = ???;
    //$delete = ????; 

    }; 

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Post the output of $_POST['option2'] so we know what data we're dealing with:
    PHP Code:
    var_dump($_POST['option2']); 


  •  

    Posting Permissions

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