| | |
MySQL Checkbox Multiple data Delete?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
what could be wrong?
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

php Syntax (Toggle Plain Text)
<?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?
check this link out
http://www.daniweb.com/techtalkforums/thread77977.html
http://www.daniweb.com/techtalkforums/thread77977.html
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
- th3 php wr3nch -
•
•
Join Date: May 2007
Posts: 81
Reputation:
Solved Threads: 1
Well i'm having a problem with the compatibility of javascript and PHP multiple delete check box.. i used a javascript for the "CHECK ALL BOXES" just like yahoo mail.. so my input is something like this "<input type='checkbox' name='checkbox' value='1'><input type='checkbox' name='checkbox' value='2'>" and the check all boxes function worked but it doesnt work with my PHP code where it is something like this :
$checked = $_POST["checkbox"];
for($i=0; $i < count($checked); $i++) {
....// DELETE ALL CHECKED
}
but if i change my input to something like: <input type='checkbox' name='checkbox[]' value='1'><input type='checkbox' name='checkbox[]' value='2'>.. it does work on my PHP script but it wont work for my "Check all Function" javascript.. damn it.. i need help!!!
$checked = $_POST["checkbox"];
for($i=0; $i < count($checked); $i++) {
....// DELETE ALL CHECKED
}
but if i change my input to something like: <input type='checkbox' name='checkbox[]' value='1'><input type='checkbox' name='checkbox[]' value='2'>.. it does work on my PHP script but it wont work for my "Check all Function" javascript.. damn it.. i need help!!!
•
•
Join Date: Dec 2008
Posts: 3
Reputation:
Solved Threads: 0
For The Check All/Uncheck All Functions.
Just Change The Name Of The Form In The Javascript And The HTML As Needed
The Javascript:
The HTML:
Just Change The Name Of The Form In The Javascript And The HTML As Needed
The Javascript:
Javascript Syntax (Toggle Plain Text)
function CheckAll() { count = document.deleteform.elements.length; for (i=0; i < count; i++) { if (document.deleteform.elements[i].checked == 0) { document.deleteform.elements[i].checked = 1; } else { document.deleteform.elements[i].checked = 1; } } } function UncheckAll() { count = document.deleteform.elements.length; for (i=0; i < count; i++) { if (document.deleteform.elements[i].checked == 1) { document.deleteform.elements[i].checked = 0; } else { document.deleteform.elements[i].checked = 0; } } }
HTML Syntax (Toggle Plain Text)
<form name="deleteform" action="somepage" method="post"> <input type="checkbox" name="ANY NAME" value="THE VALUE" /> <a href="javascript:void()" onClick = "CheckAll()">Select All</a> <a href="javascript:void()" onClick = "UncheckAll()">Select None</a> </form>
Last edited by Logan_Yupp; Dec 9th, 2008 at 7:30 pm.
•
•
Join Date: Dec 2008
Posts: 3
Reputation:
Solved Threads: 0
I've been experimenting with my php code for a while now and i found a way to perform the task of deleting the check-boxed items:
In the html, make sure all the check-boxed items have are named with brackets '[]' after the name, Like:
Post the results to the second page. In the second page, assign the posted results to a variable. In my example, the variable is $delete:
In the html, make sure all the check-boxed items have are named with brackets '[]' after the name, Like:
HTML Syntax (Toggle Plain Text)
<input type="checkbox" name="delete[]" value="THE VALUE" />
Post the results to the second page. In the second page, assign the posted results to a variable. In my example, the variable is $delete:
PHP Syntax (Toggle Plain Text)
$delete = $_POST['delete']; //Then do what you want with the selected items:// foreach ($delete as $id) { $q = "DELETE FROM table_name WHERE item_id = $id LIMIT 1"; //THE QUERY $r = @mysqli_query($DATABASE_CONNECTION, $q); //EXECUTE QUERY } //Show that the items have been successfully removed.// if (mysqli_affected_rows($DATABASE_CONNECTION) > 0) { echo '<p>The selected items have been successfully deleted.</p>'; } else { echo '<p>An error has occurred while processing your request</p>'; }
![]() |
Similar Threads
- MS Access vs. MySQL (MS Access and FileMaker Pro)
- MicroOLAP Database Designer for MySQL (Post your Resume)
- Multiple data being read in (C++)
Other Threads in the PHP Forum
- Previous Thread: How to encrpt Url parameter..??
- Next Thread: Submit Problem
| Thread Tools | Search this Thread |
ajax apache api array beginner binary broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip java javascript joomla limit link login loop mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop regex remote script search server sessions sms soap source space sql strip_tags subversion support! syntax system table template tutorial update upload url validator variable video virus web window.onbeforeunload=closeme; xml youtube





