943,095 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 433
  • PHP RSS
Feb 6th, 2010
0

help deleting a record

Expand Post »
theres nothing happen everytime i click delete.

here's my code
admin.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("reservation", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM guest order by code asc");
  11.  
  12. mysql_close($con);
  13.  
  14. <script>
  15. del=function(code){
  16. m = confirm("Are you sure you want to delete this Applicants?");
  17. if(m){
  18. document.location="deleteApplication.php?id=<?php echo $_GET['code']; ?>";
  19. }
  20. }
  21. grant=function(code){
  22. m = confirm("Are you sure you want to Grant this Applicants?");
  23. if(m){
  24. document.location="grantApplication.php?id="+code+"&page=<?php echo $_GET['code']; ?>";
  25. }
  26. }
  27. </script>
  28.  
  29. <table border='1' cellspacing='0' width='613'>
  30. <tr>
  31. <th bgcolor='green'><font color='white'>Customer Code</font></th>
  32. <th bgcolor='green'><font color='white'>First Name</font></th>
  33. <th bgcolor='green'><font color='white'>Middle Name</font></th>
  34. <th bgcolor='green'><font color='white'>Last Name</font></th>
  35. <th bgcolor='green'><font color='white'>Address</font></th>
  36. <th bgcolor='green'><font color='white'>Email Adress</font></th>
  37. <th bgcolor='green'><font color='white'>Contact No</font></th>
  38. <th bgcolor='green'><font color='white'>Remove</font></th>
  39. </tr>
  40. <?php
  41.  
  42.  
  43. $i = 0;
  44.  
  45. $number = 0;
  46. while($row = mysql_fetch_array($result)){
  47.  
  48. $number++;
  49. ?>
  50.  
  51.  
  52. <?php
  53. $i++;
  54.  
  55. if($i%2)
  56. {
  57. $bg_color = "#EEEEEE";
  58. }
  59. else {
  60. $bg_color = "#E0E0E0";
  61. }
  62. ?>
  63.  
  64. <tr bgcolor='". $bg_color ."'>
  65. <td><font color='red'><?php echo $row['code']; ?></font></td>
  66. <td><?php echo $row['fname']; ?></td>
  67. <td><?php echo $row['mname']; ?></td>
  68. <td><?php echo $row['lname']; ?></td>
  69. <td><?php echo $row['address']; ?></td>
  70. <td><?php echo $row['emailadd']; ?></td>
  71. <td><?php echo $row['contactno']; ?></td>
  72. <td><a href='javascript:del(<?php echo $row['cno']; ?>);void(0); '><font color="blue">Delete</font></a></td>
  73. </tr>
  74. <?php } ?>
  75. </table>
  76.  
  77. ?>

deleteApplication.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("reservation", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM guest order by code asc");
  11.  
  12. if (isset($_GET['code']) && is_numeric($_GET['code']))
  13. {
  14. // get id value
  15. $code = $_GET['code'];
  16.  
  17. // delete the entry
  18. $result = mysql_query("DELETE FROM guest WHERE code=$code")
  19. or die(mysql_error());
  20.  
  21. // redirect back to the view page
  22. header("Location: admin.php");
  23. }
  24. else
  25. // if id isn't set, or isn't valid, redirect back to view page
  26. {
  27. header("Location: admin.php");
  28. }
  29.  
  30.  
  31. ?>

after clicking delete theres ma message box prompt "Are you sure u want to delete this application?" Yes or No, if i click yes there's nothing happen. i want to delete the row where i select the delete button help please.
Similar Threads
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Feb 6th, 2010
0
Re: help deleting a record
without using forms i don't know how to det value. i think you must use form to get value in table.
Reputation Points: 12
Solved Threads: 27
Junior Poster
rajabhaskar525 is offline Offline
179 posts
since Nov 2009
Feb 6th, 2010
0
Re: help deleting a record
Click to Expand / Collapse  Quote originally posted by ryan311 ...
theres nothing happen everytime i click delete.

here's my code
admin.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("reservation", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM guest order by code asc");
  11.  
  12. mysql_close($con);
  13.  
  14. <script>
  15. del=function(code){
  16. m = confirm("Are you sure you want to delete this Applicants?");
  17. if(m){
  18. document.location="deleteApplication.php?id=<?php echo $_GET['code']; ?>";
  19. }
  20. }
  21. grant=function(code){
  22. m = confirm("Are you sure you want to Grant this Applicants?");
  23. if(m){
  24. document.location="grantApplication.php?id="+code+"&page=<?php echo $_GET['code']; ?>";
  25. }
  26. }
  27. </script>
  28.  
  29. <table border='1' cellspacing='0' width='613'>
  30. <tr>
  31. <th bgcolor='green'><font color='white'>Customer Code</font></th>
  32. <th bgcolor='green'><font color='white'>First Name</font></th>
  33. <th bgcolor='green'><font color='white'>Middle Name</font></th>
  34. <th bgcolor='green'><font color='white'>Last Name</font></th>
  35. <th bgcolor='green'><font color='white'>Address</font></th>
  36. <th bgcolor='green'><font color='white'>Email Adress</font></th>
  37. <th bgcolor='green'><font color='white'>Contact No</font></th>
  38. <th bgcolor='green'><font color='white'>Remove</font></th>
  39. </tr>
  40. <?php
  41.  
  42.  
  43. $i = 0;
  44.  
  45. $number = 0;
  46. while($row = mysql_fetch_array($result)){
  47.  
  48. $number++;
  49. ?>
  50.  
  51.  
  52. <?php
  53. $i++;
  54.  
  55. if($i%2)
  56. {
  57. $bg_color = "#EEEEEE";
  58. }
  59. else {
  60. $bg_color = "#E0E0E0";
  61. }
  62. ?>
  63.  
  64. <tr bgcolor='". $bg_color ."'>
  65. <td><font color='red'><?php echo $row['code']; ?></font></td>
  66. <td><?php echo $row['fname']; ?></td>
  67. <td><?php echo $row['mname']; ?></td>
  68. <td><?php echo $row['lname']; ?></td>
  69. <td><?php echo $row['address']; ?></td>
  70. <td><?php echo $row['emailadd']; ?></td>
  71. <td><?php echo $row['contactno']; ?></td>
  72. <td><a href='javascript:del(<?php echo $row['cno']; ?>);void(0); '><font color="blue">Delete</font></a></td>
  73. </tr>
  74. <?php } ?>
  75. </table>
  76.  
  77. ?>

deleteApplication.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("reservation", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM guest order by code asc");
  11.  
  12. if (isset($_GET['code']) && is_numeric($_GET['code']))
  13. {
  14. // get id value
  15. $code = $_GET['code'];
  16.  
  17. // delete the entry
  18. $result = mysql_query("DELETE FROM guest WHERE code=$code")
  19. or die(mysql_error());
  20.  
  21. // redirect back to the view page
  22. header("Location: admin.php");
  23. }
  24. else
  25. // if id isn't set, or isn't valid, redirect back to view page
  26. {
  27. header("Location: admin.php");
  28. }
  29.  
  30.  
  31. ?>

after clicking delete theres ma message box prompt "Are you sure u want to delete this application?" Yes or No, if i click yes there's nothing happen. i want to delete the row where i select the delete button help please.
how to get values with out post. for get the values there should be a form.
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Feb 6th, 2010
0
Re: help deleting a record
can you give me a sample how to delete a data sir in row of the table.
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Feb 7th, 2010
0
Re: help deleting a record
up
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008

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: Security problem, php and sessions
Next Thread in PHP Forum Timeline: Curl login authentication cookie issues





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


Follow us on Twitter


© 2011 DaniWeb® LLC