help with delete multiple rows in mysql using checkboxes

Thread Solved

Join Date: Jun 2008
Posts: 40
Reputation: enim213 is an unknown quantity at this point 
Solved Threads: 2
enim213 enim213 is offline Offline
Light Poster

Re: help with delete multiple rows in mysql using checkboxes

 
0
  #11
Aug 19th, 2008
you're welcome.! i hope i could solve my prob. too.. hehehehe
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: ersind is an unknown quantity at this point 
Solved Threads: 0
ersind ersind is offline Offline
Newbie Poster

Re: help with delete multiple rows in mysql using checkboxes

 
0
  #12
Jan 2nd, 2009
Thak you very much!

guys i just added two small variables because register globals is been removed from new version of php this will work 100%



  1. <?php
  2. $host="localhost"; // Host name
  3. $username="root"; // <strong class="highlight">Mysql</strong> username
  4. $password=""; // <strong class="highlight">Mysql</strong> password
  5. $db_name="mytest"; // Database name
  6. $tbl_name="userreg"; // Table name
  7.  
  8. // Connect to server and select databse.
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12. $sql="SELECT * FROM $tbl_name";
  13. $result=mysql_query($sql);
  14.  
  15. $count=mysql_num_rows($result);
  16.  
  17. ?>
  18. <table width="400" border="0" cellspacing="1" cellpadding="0">
  19. <tr>
  20. <td><form name="form1" method="post" action="">
  21. <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  22. <tr>
  23. <td bgcolor="#FFFFFF">&nbsp;</td>
  24. <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
  25. </tr>
  26. <tr>
  27. <td align="center" bgcolor="#FFFFFF">#</td>
  28. <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
  29. <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
  30. <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
  31. <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
  32. </tr>
  33. <?php
  34. while($rows=mysql_fetch_array($result)){
  35. ?>
  36. <tr>
  37. <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
  38. <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
  39. <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td>
  40. <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td>
  41. <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
  42. </tr>
  43. <?php
  44. }
  45. ?>
  46. <tr>
  47. <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
  48. </tr>
  49. <?
  50. // Check if <strong class="highlight">delete</strong> button active, start this
  51. $delete = $_POST[delete];
  52. $checkbox = $_POST[checkbox];
  53. if($delete){
  54. for($i=0;$i<$count;$i++){
  55. $del_id = $checkbox[$i];
  56. $sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
  57. $result = mysql_query($sql);
  58. }
  59.  
  60. // if successful redirect to delete_multiple.php
  61. if($result){
  62. echo "<meta http-equiv=\"refresh\" content=\"0;URL=test.php\">";
  63. }
  64. }
  65. mysql_close();
  66. ?>
  67. </table>
  68. </form>
  69. </td>
  70. </tr>
  71. </table>
Last edited by ersind; Jan 2nd, 2009 at 10:49 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

Re: help with delete multiple rows in mysql using checkboxes

 
0
  #13
Jun 14th, 2009
nice code. workd for me enim213!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 40
Reputation: enim213 is an unknown quantity at this point 
Solved Threads: 2
enim213 enim213 is offline Offline
Light Poster

Re: help with delete multiple rows in mysql using checkboxes

 
1
  #14
Jun 15th, 2009
Originally Posted by SKANK!!!!! View Post
nice code. workd for me enim213!
thank. glad to help. - enim213
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: falguni dattani is an unknown quantity at this point 
Solved Threads: 0
falguni dattani falguni dattani is offline Offline
Newbie Poster

Re: help with delete multiple rows in mysql using checkboxes

 
0
  #15
Jul 31st, 2009
hey buddy enim,thanks. itz really a very good code and it workd for me too.
thanks again
god bless u
Last edited by falguni dattani; Jul 31st, 2009 at 8:52 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: falguni dattani is an unknown quantity at this point 
Solved Threads: 0
falguni dattani falguni dattani is offline Offline
Newbie Poster

Re: help with delete multiple rows in mysql using checkboxes

 
0
  #16
Jul 31st, 2009
but u solved my prob. so how can u say that u solved yr prob!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 40
Reputation: enim213 is an unknown quantity at this point 
Solved Threads: 2
enim213 enim213 is offline Offline
Light Poster

Re: help with delete multiple rows in mysql using checkboxes

 
0
  #17
Aug 1st, 2009
i did too.. that was way back then..
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 10
Reputation: kiranhg.2008 is an unknown quantity at this point 
Solved Threads: 0
kiranhg.2008 kiranhg.2008 is offline Offline
Newbie Poster
 
0
  #18
13 Days Ago
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\kregpho.php:2) in D:\xampp\htdocs\kregpho.php on line 72


can any 1 tell me wat this error mean....y should it occur.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 431
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training
 
0
  #19
13 Days Ago
Originally Posted by kiranhg.2008 View Post
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\kregpho.php:2) in D:\xampp\htdocs\kregpho.php on line 72


can any 1 tell me wat this error mean....y should it occur.
It means that you use a header function (header(), setcookie(), session_start(), etc...) after you started sending content. After you start sending content, the headers can not be modified.

And by "sending content", I mean anything that would show up in the browsers "view source" output. Even a white-space before your opening <?php tags would cause this error.

P.S.
Why did you post this into an old, random thread?
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training
 
0
  #20
12 Days Ago
because everyone is subscribed to it and he knos it
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC