I have this table table and i want when to check a checkbox to insert(or update) into the post_check database field with the values checked or unchecked (without submit button) correspondingly of the checkbox . I write this code but i have stack for a long time because:The values didn't pass to database, the tick mark didn't stay in checkbox (even i made reload with header() function)
<form action="" method="post">
<table class="table table-bordered table-hover" id="pinakas">
<thead>
<tr>
<th class="titlos"><input style="margin-left: 3px;" type="checkbox" name="checkboxAllBoxes" id="checkboxAllBoxes "></th>
<th class="titlos">POST_ID</th>
<th class="titlos">ΚΑΤΗΓΟΡΙΑ</th>
<th class="titlos">ΤΙΤΛΟΣ</th>
<th class="titlos">ΚΕΙΜΕΝΟ</th>
<th class="titlos">FILE</th>
<th class="titlos">ΕΚΔΟΤΗΣ</th>
<th class="titlos">ΗΜΕΡ.</th>
<th class="titlos">UPDATE</th>
<th class="titlos">DELETE</th>
</tr>
</thead>
<?php
global $connect;
$query="SELECT * FROM posts ORDER BY post_date DESC ";
$select_posts= mysqli_query($connect, $query);
while($row= mysqli_fetch_assoc($select_posts)) {
$post_id=$row['post_id'];
$post_cat_title=$row['post_cat_title'];
$post_title=$row['post_title'];
$post_keimeno= substr($row['post_keimeno'], 0, 60);
$post_publisher=$row['post_publisher'];
$post_image=$row['post_image'];
$post_date=$row['post_date'];
$post_check=$row['post_check'];
echo "<tr>";?>
<td><input type='checkbox' name="checkbox" id="<?php echo $post_id; ?>" value="<?php echo $value; ?>" onchange="check(this);" ></td>;
<?php
echo "<td class='keli'><strong>$post_id</td>";
echo "<td class='keli'>$post_cat_title</td>";
echo "<td class='keli'>$post_title</td>";
echo "<td class='keli'>$post_keimeno</td>";
echo "<td><img src='../images/$post_image' height='50' witdth='50'></td>";
echo "<td class='keli'>$post_publisher</td>";
echo "<td class='keli'>$post_date</td>";
?>
<td><a href="tables.php?source=tables&update=<?php echo $post_id; ?>">UPDATE</a></td>
<td><a href="tables.php?source=tables&delete=<?php echo $post_id; ?>">Delete</a></td>
</tr>
<?php
}
?>
</table>
</form>
<div class="button">
<!--<button class="koumpi" type="submit" name="submit">SUBMIT</button>-->
<button type="submit" name="delete"class="btn btn-primary">Delete</button>
<button type="submit" class="btn btn-primary" name="update" style="background-color: green;">UPDATE</button>
<button type="submit" class="btn btn-primary">Submit Button</button>
</div>
<!--/.row-->
<!--/.main-->
<script>
function check(ch){
if(ch.checked){
window.location.href = "tables.php?source=tables&checkbox="+ch.id+"&value=checked";
//windows.location.replace("http://yahoo.com");
}
else{
window.location.href = "tables.php?source=tables&checkbox="+ch.id+"&value=unchecked";
}
}
</script>
Aucun commentaire:
Enregistrer un commentaire