vendredi 26 décembre 2014

Php update checkbox states in db

I am new in php, i have a question. How can I update checkbox states in db? checkboxes have same name. when click on update button it will update all row checkboxes stat in db. and checkboxes in db get true or false


html part



<div class='blocks-output'>
<form action='/admin/blocks' method='post'>
<input type='hidden' name='updated_block_index' value=''/>
<input type='hidden' name='updated_block_name' value=''/>
<table class='table table-hover table-striped table-bordered'>
<thead>
<tr class='text-uppercase'>
<td>#</td>
<td>selected</td>
<td>block index</td>
<td>block name</td>
<td>edit</td>
<td>delete</td>
</tr>
</thead>
<tbody>
<?php foreach ($blocksInfo as $row) { ?>
<tr>
<td>
<?php echo $row['id']; ?>
</td>
<td>
<input type="checkbox" name='id' value='<?php echo $row['id']; ?>' <?php if($row['selected'] == 1) echo 'checked'; ?> />
</td>
<td>
<p><?php echo $row['block_index']; ?></p>

<div class='form-group hidea'>
<input type='number' class='form-control' name='block_index' placeholder='Block index' value='<?php echo $row['block_index']; ?>'>
</div>
</td>
<td>
<p><?php echo $row['block_name']; ?></p>

<div class='form-group hidea'>
<input type='text' class='form-control' name='block_name' placeholder='Block name' value='<?php echo $row['block_name']; ?>'>
</div>
</td>
<td>
<a href='' class='edit-row btn btn-primary' role='button'>edit</a>
<button class='update-row btn btn-primary' name='update_row' value='<?php echo $row['id']; ?>'>update</button>
</td>
<td>
<button type='submit' class='btn btn-primary' name='delete_row' value='<?php echo $row['id']; ?>'>delete</button>
</td>
</tr>
<?php } ?>

<tr>
<td>
<input type='submit' class='btn btn-primary' name='clear_table' value='delete all'>
</td>
<td></td>
<td></td>
<td></td>
<td ></td>
<td>
<input type='submit' class='btn btn-primary' name='update_table' value='update'>
</td>
</tr>
</tbody>
</table>
</form>
</div>


enter image description here


thank you :)





Aucun commentaire:

Enregistrer un commentaire