Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> Zadanie 6.1 </title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "";
  11. $dbname = "studenci";
  12.  
  13. $conn = new mysqli($servername, $username, $password, $dbname);
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18.  
  19. $sql = "SELECT idstudent, imie, nazwisko, grupa FROM student";
  20. $result = $conn->query($sql);
  21.  
  22. echo "<table border='1'>";
  23. echo '<tr>';
  24. echo '<td> idstudent </td>';
  25. echo '<td> imie </td>';
  26. echo '<td> nazwisko </td>';
  27. echo '<td> grupa </td>';
  28.  
  29. echo '</tr>';
  30. if ($result->num_rows > 0) {
  31. while($row = $result->fetch_assoc()) {
  32. $id = $row['idstudent'];
  33. echo "<tr><td>" . $row["idstudent"]. " </td><td> " . $row["imie"]. " </td><td> " . $row["nazwisko"]. " </td><td> "
  34. .$row['grupa']. "</td>".'<td><a href="strona_usuwajaca_rekord.php?action=delete&id='.$id.'"><img src= cross.png width = 30px height = 30px></img></td></tr>';
  35. }
  36. } else {
  37. echo "0 results";
  38. }
  39.  
  40. echo '</table>';
  41.  
  42.  
  43.  
  44.  
  45. $conn->close();
  46. ?>
  47. <fieldset>
  48. <legend> Dodaj studenta </legend>
  49. <form action ="dodawanie.php" method ="POST">
  50. <input type="submit" value="dodaj studenta"><br>
  51. </form>
  52. </fieldset>
  53. </body>
  54. </html>
  55. -----------------------------------------------------------
  56. --------------------------------------------------------------
  57.  
  58. <?php
  59. $servername = "localhost";
  60. $username = "root";
  61. $password = "";
  62. $dbname = "studenci";
  63.  
  64. $conn = new mysqli($servername, $username, $password, $dbname);
  65. if ($conn->connect_error) {
  66. die("Connection failed: " . $conn->connect_error);
  67. }
  68.  
  69. if ($_GET['action']=='delete' && isset($_GET['id'])) {
  70. $id = (int) $_GET['id'];
  71. $zapytanie = "DELETE FROM student WHERE idstudent = {$id}";
  72. $conn->query($zapytanie);
  73. header("Location: form1.php");
  74. }
  75. $conn->close();
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement