Advertisement
Guest User

Untitled

a guest
Jan 12th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Zadanie 7.1.0</title>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="refresh" content="1; http://localhost/SebastianBialuchaZad7_1_0.php" />
  6. </head>
  7. <body>
  8.  
  9. <?php
  10.     $servername = "localhost";
  11.     $username = "root";
  12.     $password = "";
  13.     $dbname = "baza danych";
  14.  
  15.  
  16.     $conn = new mysqli($servername, $username, $password, $dbname);
  17.     if ($conn->connect_error) {
  18.         die("Connection failed: " . $conn->connect_error);
  19.     }
  20.  
  21.     $sql = "SELECT * from studenci";
  22.     $result = $conn->query($sql);
  23.  
  24.     if ($result->num_rows > 0) {
  25.         while($row = $result->fetch_assoc()) {
  26.             echo $row["id"]. ". " . $row["imie"]. " " . $row["nazwisko"];
  27. ?>
  28. <a href="localhost/SebastianBialuchaZad7_1_0.php?id=$_GET['id']"><img src='crossmark.png' width='12' height='12' alt='crossmark'> </a><br>;
  29. <?php
  30.         }
  31.     } else {
  32.         echo "0 results";
  33.     }  
  34.     if(isset($_GET['id'])) {
  35.     $delete_id = mysql_real_escape_string($_GET['id']);
  36.     $sql = mysql_query("DELETE FROM studenci WHERE id = '".$delete_id."'");
  37.     if($sql) {
  38.         echo "<br/><br/><span>deleted successfully...!!</span>";
  39.     } else {
  40.         echo "ERROR";
  41.     }
  42. }
  43.     $conn->close();
  44. ?>
  45.  
  46. <form action="SebastianBialuchaZad7_1_1.php" method="post">
  47.     <input type="submit" value="Dodaj nowego studenta" />
  48. </form>
  49.  
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement