943,107 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2042
  • PHP RSS
Mar 5th, 2010
0

how to delete a data using checkbox

Expand Post »
i have a problem deleting a data using checkbox please help me

here's my code

admin.php
PHP Syntax (Toggle Plain Text)
  1. <form id="form1" name="form1" method="post" action="deleteApplication.php"><table border='1' cellspacing='0' width='612'>
  2. <tr>
  3. <th bgcolor='green'><font color='white'>#</font></th>
  4. <th bgcolor='green'><font color='white'>Room No.</font></th>
  5. <th bgcolor='green'><font color='white'>Cust. Code</font></th>
  6. <th bgcolor='green'><font color='white'>Check In</font></th>
  7. <th bgcolor='green'><font color='white'>Check Out</font></th>
  8. <th bgcolor='green'><font color='white'>No of Rooms</font></th>
  9. <th bgcolor='green'><font color='white'>Room Type</font></th>
  10. <th bgcolor='green'><font color='white'>Function</font></th>
  11. </tr>
  12. <?php
  13. $i = 0;
  14.  
  15. $number = 0;
  16. while($row = mysql_fetch_array($result)){
  17.  
  18. $number++;
  19.  
  20. ?>
  21.  
  22. <?php
  23. $i++;
  24.  
  25. if($i%2)
  26. {
  27. $bg_color = "#EEEEEE";
  28. }
  29. else {
  30. $bg_color = "#E0E0E0";
  31. }
  32. ?>
  33.  
  34. <tr bgcolor='". $bg_color ."'>
  35. <td><center><Strong><font color='red'><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['cno']; ?>">
  36. </font></Strong>
  37. </center></td>
  38. <td><center><Strong><font color='red'><?php echo $row['roomno']; ?></font></Strong></center></td>
  39. <td><center><Strong><font color='red'><?php echo $row['cno']; ?></font></Strong></center></td>
  40. <td><center><Strong><?php echo $row['checkin']; ?></Strong></center></td>
  41. <td><center><Strong><?php echo $row['checkout']; ?></Strong></center></td>
  42. <td><center><Strong><?php echo $row['noofrooms']; ?></Strong></center></td>
  43. <td><center><Strong><?php echo $row['roomtype']; ?></Strong></center></td>
  44. <td><div align="center"><a href='edit.php?code=<?php echo $row[cno]; ?>' class="style1"><img src="Admin/img/save-icon.gif" width="16" height="16" alt="View" title="View Information"/></a>
  45. <a href='sendmail.php?emailadd=<?php echo $row[emailadd]; ?>' class="style1"><img src="Admin/img/edit-icon.gif" width="16" height="16" alt="Email" title="Email"/></a></div></td>
  46. </tr>
  47. <?php } ?>
  48. </table>
  49. <div class="select"><strong>Other Pages: </strong>
  50. <select>
  51. <option>1</option>
  52. </select>
  53. </div>
  54.  
  55. <label>
  56. <input name="delete" type="submit" id="delete" value="Delete">
  57.  
  58.  
  59. </label></form>

deleteApplication.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include 'dbconnect.php';
  3.  
  4. if(isset($_POST['delete']))
  5. {
  6. $checkbox = $_POST['checkbox']; //from name="checkbox[]"
  7. $countCheck = count($_POST['checkbox']);
  8.  
  9. for($i=0;$i<$countCheck;$i++)
  10. {
  11. $del_id = $checkbox[$i];
  12.  
  13. $sql = "DELETE from rent where cno = $del_id";
  14. $result = mysql_query($sql) or die (mysql_error());
  15.  
  16. }
  17. if($result)
  18. {
  19. header('Location: index.php');
  20. }
  21. else
  22. {
  23. echo "Error: ".mysql_error();
  24. }
  25. }
  26. ?>

nothings happen everytime i click delete.
Similar Threads
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Mar 6th, 2010
0
Re: how to delete a data using checkbox
PHP Syntax (Toggle Plain Text)
  1. if(isset($_POST['delete'])) {
  2. foreach($_POST['checkbox'] as $id){
  3. mysql_query("DELETE from rent WHERE cno = '.$id.'");
  4. )
  5. }
Reputation Points: 11
Solved Threads: 4
Junior Poster
sacarias40 is offline Offline
113 posts
since Nov 2008
Mar 6th, 2010
0
Re: how to delete a data using checkbox
nothings happen

here's my deleteapplication.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include 'dbconnect.php';
  3.  
  4.  
  5. if(isset($_POST['delete'])) {
  6.  
  7. foreach($_POST['checkbox'] as $cno){
  8.  
  9. mysql_query("DELETE from rent WHERE cno = '.$cno.'");
  10. }
  11. header('Location: admin.php');
  12.  
  13. }
  14. ?>

there's no deletion. T_T
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Mar 6th, 2010
0
Re: how to delete a data using checkbox
i miss 1 its work now thanks
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Feb 13th, 2011
0
Re: how to delete a data using checkbox
Still nothings happen! What are you missing!
Reputation Points: 10
Solved Threads: 0
Junior Poster
cliffcc is offline Offline
100 posts
since Feb 2011
Oct 26th, 2011
0
Re: how to delete a data using checkbox
are those members still active in here??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
celz is offline Offline
1 posts
since Oct 2011

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: php select from 2 different tables
Next Thread in PHP Forum Timeline: Integrate Real-Time Feed to website





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


Follow us on Twitter


© 2011 DaniWeb® LLC