vendredi 19 février 2016

Multiple checkboxes update in DB with ENUM and Custom column

I have an table where custom columns where made by administrators, every column have hiis own enum with '0','1'. Here you can choose if the column is true or false.

Now i want te make a option where administrators can update this true or false by a checkbox.

The Checkbox.

<div class="col-sm-9">
    <?php
    if(isset($produci[0])) {
    foreach($produci as $key => $avlue) {
    ?>
    <div class="row-fluid">
       <label>
           <input name="clickedproduct[]" type="checkbox" value="<?php echo $avlue['name']; ?>" <?php echo (($_SERVER['REQUEST_METHOD'] == 'POST') ? ((isset($_POST[$avlue['name']])) ? ' value="'.$avlue[$avlue['name']].'" checked' : ' value="'.$avlue[$avlue['name']].'"') : (($avlue[$avlue['name']] == '1') ? ' value="'.$avlue[$avlue['name']].'"checked' : ' value="'.$avlue[$avlue['name']].'"')); ?>>
           <?php echo $avlue['name']; ?>
      </label>                                    
    </div> 
    <?php } }else{
                  echo '<font color="red">Er zijn nog geen producten aangemaakt.</font>';
                 } ?>                           
</div>

My PDO.

if(isset($_POST['clickedproduct']))
  {  $values = array();
  foreach($_POST['clickedproduct'] as $access )
  { 
    $clickedproduct = '0'; // = bijv. 1 of 0
    $column = $access; // = bijv. product
  } // end of foreach.


    $product_access = $dbh->prepare("UPDATE products_access SET `{$column}` = :enum WHERE products_access.id = :id");
    $product_accessvar = trim($user['id']);
    $product_access->bindParam(':id', $product_accessvar, PDO::PARAM_INT);
    $product_access->bindParam(':enum', $clickedproduct, PDO::PARAM_INT); 
    $product_access->execute();
}

Is there someone with an solution?




Aucun commentaire:

Enregistrer un commentaire