Hi to everyone I’m wondering how to make some simple checkbox for multiple data delete from mysql I found some tutorial on net but don’t work. I tested it without changing anything and doesn’t work. I’m wondering did programmer test it before he posted that tutorial ?
Here is a link of that tutorial if u don’t believe me test it.
phpeasystep.com
I’m working on some cms tool to make posts on site I used a lot of cms like Joomla, WordPress and Textpattern. Now I want to make something like that, of course not even similar to that but just for my personal use and fun.
2 things to do:
- Option to select all checkboxes. I like something like in joomla in top there is checkbox with titles when u select it all checkbox are selected and if u uncheck it all is unchecked
- When I press delete button all checkboxes that I select are deleted from database or moved to some other category like trash which is nice because u can in that way return some posts that u delete by mistake or some other reason
Here is my code that bothers me becouse checkboxes don't work :(
<?php
include ('conf/config.php');
include('conf/opendb.php');
$sql="SELECT id, title, author, DATE_FORMAT(date, '%M %d, %Y') as sd FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table border="0" cellpadding="0" cellspacing="0" class="adminlist">
<tr id="top">
<th width="5" align="center">Id</th>
<th width="5" align="center">#</th>
<th>Title</th>
<th width="200" align="center">Author</th>
<th width="100" align="center">Date</th>
<th width="80" align="center">Delete</th>
<th width="20" align="center">Edit</th>
</tr>
<?php
while($rows = mysql_fetch_array($result)){
?>
<tr>
<td width="5" align="center"><? echo $rows['id']; ?></td>
<td width="5" align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td><? echo $rows['title']; ?></td>
<td width="200" align="center"><? echo $rows['author']; ?></td>
<td width="100" align="center"><? echo $rows['sd']; ?></td>
<td width="80" align="center" id="trash"><a href="delete_news.php?id=<? echo $rows['id']; ?>">Delete</a></td>
<td width="20" align="center" id="edit"><a href="edit_news.php?id=<? echo $rows['id']; ?>">Edit</a></td>
<?php
}
?>
<tr>
<td colspan="7" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=post_manage.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
what could be wrong?