By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

Deleting entries

P: 3
I am new to PHP and I am trying make a page that displays the entries in a table and then gives the option to delete a specific entry after checking it. I can get the page to display the entries and there is a link to delete the entry but it will not pass the variable to the second page that deletes the entry. Here is my code.

This is the page that displays the entries:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include 'datacon.php';
  3.  
  4. $result = mysql_query("SELECT * FROM stationfailuretest");
  5.  
  6. echo "<table border='1'>
  7. <tr>
  8. <th>Station Failures</th>
  9. <td>ID</td>
  10. <td>Cube Number</td>
  11. <td>Phone Number</td>
  12. <td>Agent Name</td>
  13. <td>Agent ID</td>
  14. <td>Problem</td>
  15. </tr>";
  16.  
  17. while($row = mysql_fetch_array($result))
  18.   {
  19.   echo "<tr>";
  20.   echo "<td><a href=\"list2.php?ID=";
  21.   echo $row['id'];
  22.   echo "\" TARGET=main>";
  23.   echo "Delete</a></td>";
  24.   echo "<td>".$row['id']."</td>\n";
  25.   echo "<td>".$row['Cube_Number']."</td>\n";
  26.   echo "<td>".$row['Phone_Number']."</td>\n";
  27.   echo "<td>".$row['Agent_Name']."</td>\n";
  28.   echo "<td>".$row['Agent_ID']."</td>\n";
  29.   echo "<td>".$row['Problem']."</td>\n";
  30.   echo "</tr>";
  31.   }
  32. echo "</table>";
  33.  
  34. mysql_close($con);
  35. ?>
  36.  
  37. Here is the code of the page that is supposed to delete the entry:
  38.  
  39. <?php
  40.  
  41. switch (ID)
  42. {
  43. default:
  44. echo "<b>";
  45. include 'datacon.php';
  46.  
  47. $result = mysql_query("DELETE FROM stationfailuretest WHERE id = '".$ID."'");
  48.  
  49. mysql_close($con);
  50. break;
  51. }
  52. ?>

If I hard code the number of the ID into the second page it deletes the entry but not if I leave it to use the passed variable.

Please Help
Jul 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: 3
I changed the second page to:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($id=="")
  3. header("Refresh: 0;url=work.html");
  4. else
  5. {
  6. include 'datacon.php';
  7.  
  8. $query = "delete from stationfailuretest where id='".$id."'";
  9. $result = mysql_query($query);
  10. header("Refresh: 0;url=index.php");
  11. }
  12. ?>
That way I could test to see if the variable is even passed and it comes up with the work.html. So for some reason the variable is not being passed.

Thanks again
Jul 20 '07 #2

P: 3
actually i found the problem, thank you
Jul 20 '07 #3

pbmods
Expert 5K+
P: 5,821
Heya, 66sprite. Welcome to TSDN!

Well, glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 21 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.