Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Update multiple rows with multiple fields from a form into MySQL based on checkboxes

$
0
0

Hello .. I need some help with this .. I have a user database where an admin can add/delete users and search for them on a website.. 

 

What i want is a possibility to update user details..

 

Its a little hard to explain but heres a screenshot

 

 

Unavngivet12.jpg

 

As you can see i have some fields that is editable .. Those fields are generated based on what you search for on the page before.. On the top row you can see two buttons: "Slet"(delete) and "Gem" (save) .. On the first collum all to the left you can see a checkbox.. As it is now, a user can mark this checkbox and click delete, which deletes the marked users from the database .. What i want also is if a user has edited some information in the fields AND marked the checkbox to the left of the edited fields AND clicked "Gem" (save) the rows with the marked users should be updated with the new information in the database..

 

I just have no idea how to do this.. 

 

Heres the code for the delete button:

 

if($_POST['delete']){
  
    $idList = join (',', array_map('intval', $_POST['checkbox']));
    
    $sql = "DELETE FROM `users` WHERE `userid` IN ($idList)";
    mysql_query($sql);
    
    echo "* - De markerede brugere blev slettet!";
    include "includes/redirection_admin.php";
    
} 

 

At first i thought it would be as simple as to just change the sql query to UPDATE instead but that doesnt work .. 

 

This is what i have made:

 

    $idList = join (',', array_map('intval', $_POST['checkbox']));
    
    
    $sql = "UPDATE `users` 
            SET `fornavn`='$userid' IN '$fornavn', `efternavn` IN '$efternavn', `cprnr` IN '$cprnr', `adresse` IN '$adresse', `postnr` IN '$postnr', `by` IN '$by', `tlfnr` IN '$tlfnr', `email` IN '$email', `userid` IN '$userid'
            WHERE `userid` IN ($idList)";
    mysql_query($sql);
    
    echo "* - De markerede brugere fik opdateret deres oplysninger!";

 

But that doesnt work .. The fields doesnt change

 

Can anyone assist ?


Viewing all articles
Browse latest Browse all 13200

Trending Articles