943,682 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 8480
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 19th, 2008
0

Re: help with delete multiple rows in mysql using checkboxes

you're welcome.! i hope i could solve my prob. too.. hehehehe
Reputation Points: 11
Solved Threads: 2
Light Poster
enim213 is offline Offline
40 posts
since Jun 2008
Jan 2nd, 2009
0

Re: help with delete multiple rows in mysql using checkboxes

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%



php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ersind is offline Offline
1 posts
since Jan 2009
Jun 14th, 2009
0

Re: help with delete multiple rows in mysql using checkboxes

nice code. workd for me enim213!
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Jun 15th, 2009
1

Re: help with delete multiple rows in mysql using checkboxes

Click to Expand / Collapse  Quote originally posted by SKANK!!!!! ...
nice code. workd for me enim213!
thank. glad to help. - enim213
Reputation Points: 11
Solved Threads: 2
Light Poster
enim213 is offline Offline
40 posts
since Jun 2008
Jul 31st, 2009
0

Re: help with delete multiple rows in mysql using checkboxes

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
falguni dattani is offline Offline
2 posts
since Jul 2009
Jul 31st, 2009
0

Re: help with delete multiple rows in mysql using checkboxes

but u solved my prob. so how can u say that u solved yr prob!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
falguni dattani is offline Offline
2 posts
since Jul 2009
Aug 1st, 2009
0

Re: help with delete multiple rows in mysql using checkboxes

i did too.. that was way back then..
Reputation Points: 11
Solved Threads: 2
Light Poster
enim213 is offline Offline
40 posts
since Jun 2008
Nov 14th, 2009
0
Re: help with delete multiple rows in mysql using checkboxes
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.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
kiranhg.2008 is offline Offline
11 posts
since Nov 2009
Nov 14th, 2009
0
Re: help with delete multiple rows in mysql using checkboxes
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?
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Nov 15th, 2009
0
Re: help with delete multiple rows in mysql using checkboxes
because everyone is subscribed to it and he knos it
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Update values
Next Thread in PHP Forum Timeline: Getting str_replace function on ' sign





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC