Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php + mysql]Usuwanie wierszy MySQL przez php
eXido
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.04.2006

Ostrzeżenie: (0%)
-----


Witam,

Przygode z php i SQL zaczalem dopiero tydzine temu, wiec prosze o wyrozumialosc.

Troche opisze sytuacje: Mam tabele w MySQL zwana 'Hirer' która zawiera informacje takie jak adres zamieszkania, telefon, email itd.
Kazdy wiersz w tej tabeli jest identyfikowany przez pole 'HirerID' które jest auto_increment primary key.

Teraz, zrobilem w php skrypt który wyswietla na stronie wszystkich Hirer'ów w tej tabeli. Jednak chce zeby na koncu kazdego wiersza miec link który skasuje z tej tabeli dany wiersz, jednak link ten nie dziala.

Bylbym wdzieczny gdyby ktos mógl podac gdzie mam blad i jak powinna ta strona wygladac by poprawnie dzialala:

  1. <html>
  2. <head>
  3.  
  4. </head>
  5. <body>
  6.  
  7. <?php
  8.  
  9. $dbcnx= @mysql_connect('localhost', 'root', 'laptop55');
  10. if (!$dbcnx) {
  11. exit('<p>Unable to connect to the database server at this time.</p>');
  12. }
  13.  
  14. if (!@mysql_select_db('Village_Hall')) {
  15. exit('<p>Unable to locate the Village Hall database at this time.</p>');
  16. }
  17.  
  18.  
  19.  
  20.  
  21. //removing deleted hirers if set
  22.  
  23. if (isset($_GET['deletehirer'])) {
  24. $HirerID = $row['HirerID'];
  25. $sql = "DELETE FROM Hirer WHERE HirerID=$HirerID";
  26. if (@mysql_query($sql)) {
  27. echo '<p> The Hirer has been removed from the database.</p>';
  28. } else {
  29. echo '<p> Error removing Hirer from database: ' . mysql_error() . '</p>';
  30. }
  31. }
  32. ?>
  33.  
  34. <!-- show Hirers currently in the database -->
  35.  
  36. Here are all the hirers currently in the database:</p>
  37. <?php
  38.  
  39. $result = @mysql_query('select HirerID, Title, Surname, Forename, Street_Number, Town_City, County, Post
    Code, Home_Tel, 
  40.  
  41. Mobile_Tel, Email from Hirer');
  42. if (!$result) {
  43. exit('<p>Error performing query: ' . mysql_error() . '</p>');
  44. }
  45.  
  46. while ($row = mysql_fetch_array($result)) {
  47.  
  48. ?>      <table width="85%" valign="center"><tr><td width="10">      <?php
  49.  
  50.  
  51. echo $row['HirerID']; ?> </td> 
  52.  
  53.  
  54. <td width="15"> <?php echo $row['Title']; ?> </td> 
  55.  
  56.  
  57. <td width="20"> <?php  echo $row['Surname']; ?> </td>  
  58.  
  59.  
  60. <td width="20"> <?php echo $row['Forename']; ?> </td> 
  61.  
  62.  
  63. <td width="10"> <?php echo $row['Street_Number']; ?> </td> 
  64.  
  65.  
  66. <td width="20"> <?php echo $row['Street_Name']; ?> </td> 
  67.  
  68.  
  69. <td width="20"> <?php echo $row['Town_City']; ?> </td> 
  70.  
  71.  
  72. <td width="20"> <?php echo $row['County']; ?> </td> 
  73.  
  74.  
  75. <td width="20"> <?php echo $row['PostCode']; ?></td> 
  76.  
  77.  
  78. <td width="20"> <?php echo $row['Home_Tel']; ?></td> 
  79.  
  80.  
  81. <td width="25"> <?php echo $row['Mobile_Tel']; ?></td> 
  82.  
  83.  
  84. <td width="25"> <?php echo $row['Email']; ?></td>
  85.  
  86.  
  87. <!-- set to delete Hirer on click -->
  88.  
  89. <td width="25"> <?php echo ' <a href="' . $_SERVER['PHP_SELF'] .
  90. '?deletehirer=' . $HirerID . '">' .
  91. 'Remove Hirer</a>'; 
  92. ?>
  93.  
  94.    </td>
  95.  
  96.  
  97.      </table>    <?php
  98.  
  99.  
  100. }
  101. ?>
  102.  
  103.  
  104.  
  105. </body>
  106. </html>


Dziekuje i pozdrawiam,

eXido

Ten post edytował eXido 20.04.2006, 14:54:49
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.09.2025 - 07:27