php - How to delete checked row from db -
i have deleting sql can't seem find out why it's not working :/
after trying delete checked row if($result) reload page row still there ... :/
can please help me ? missing ?
<form name="delete_posts" method="post" action=""> <table class="all_posts"> <tr> <td class="checkbox"><input type="checkbox" name="select_all" id="select_all" /></td> <td class="post_title">title</td> <td>auther</td> <td>posted</td> <td>updated</td> <td>category</td> </tr> <tr><td class="delete_posts" colspan="6"><input name="delete" type="submit" id="delete" value="delete"></td></tr> <?php $post_set = get_all_posts(); while ($row = mysqli_fetch_array($post_set)){ echo "<tr> <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=".$row['id']."></td> <td><a href=\"edit_post.php?edit=".$row['id']."\">" .$row['title']. "</td> <td>auther</td> <td>".date("d. m. 'y", strtotime($row["date"]))."</td> <td>update date</td> <td>".str_replace("_"," ",$row['category'])."</td> </tr>";} // delete posts if(isset($_post['delete'])){ $checkbox = $_post['delete']; $count = count($checkbox); for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "delete posts id = $del_id "; $result = mysqli_query($connection, $sql); } // if successful redirect delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;url=posts.php\">"; } } ?> </table> </form>
thanx helping
cheers chris
i think have error in code retrive checked row : instead of getting checkbox values ($checkbox = $_post['checkbox'];
) getting delete value ($checkbox = $_post['delete'];
).
here corrected part :
if(isset($_post['delete'])){ $checkbox = $_post['checkbox']; $count = count($checkbox); for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "delete posts id = $del_id "; $result = mysqli_query($connection, $sql); }
php checkbox delete-row sql-delete
No comments:
Post a Comment