Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. Index.php
  2. <?php
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "uuu";
  7.  
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10. // Check connection
  11. if ($conn->connect_error) {
  12.     die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. $sql = "INSERT INTO dane (ident, uwagi, serwis)
  16. VALUES ('$_POST[ident]','$_POST[uwagi]','$_POST[serwis]')";
  17.  
  18. if ($conn->query($sql) === TRUE) {
  19.     echo "New record created successfully";
  20. } else {
  21.     echo "Error: " . $sql . "<br>" . $conn->error;
  22. }
  23.  
  24. $conn->close();
  25.  
  26. header('location:index.php');
  27.  
  28. ?>
  29.  
  30.  
  31. Dane.php
  32. <?php
  33. $servername = "localhost";
  34. $username = "root";
  35. $password = "";
  36. $dbname = "uuu";
  37.  
  38. // Create connection
  39. $conn = new mysqli($servername, $username, $password, $dbname);
  40. // Check connection
  41. if ($conn->connect_error) {
  42.     die("Connection failed: " . $conn->connect_error);
  43. }
  44.  
  45. $sql = "SELECT id, ident, uwagi, serwis FROM dane";
  46. $result = $conn->query($sql);
  47. echo '<form action="delete.php" method="POST">';
  48. echo '<table><tr><th>LP</th><th>ID</th><th>Uwagi</th><th>Serwis</th></tr>';
  49. if ($result->num_rows > 0) {
  50.     // output data of each row
  51.     while($row = $result->fetch_assoc()) {
  52.         echo "<tr><td>{$row['id']}</td><td>{$row['ident']}</td><td>{$row['uwagi']}</td><td>{$row['serwis']}</td><td><td><input type='checkbox' value ='" . $row['id'] . "' name='kasuj[]'></td></tr>";
  53. }
  54. echo '</table>';
  55. echo "<input type='submit' name='delete' value='delete'>";    
  56. }
  57.  
  58. else {
  59.     echo "0 results";
  60. }
  61.  
  62. $conn->close();
  63. ?>
  64. <?php
  65.  
  66.  
  67. delete.php
  68. <?php
  69. $servername = "localhost";
  70. $username = "root";
  71. $password = "";
  72. $dbname = "uuu";
  73.  
  74. $conn = new mysqli($servername, $username, $password, $dbname);
  75. // Check connection
  76. if ($conn->connect_error) {
  77.     die("Connection failed: " . $conn->connect_error);
  78. }
  79.  
  80.  
  81. if(isset($_POST['delete'])){
  82.    
  83.    foreach ($_POST["kasuj"] as $id){
  84.    $sql = "DELETE FROM dane WHERE id='$id'";
  85.     mysqli_query($conn,"$sql * FROM dane");
  86. }
  87.    echo "Wpis skasowany";
  88. }
  89.  
  90. $conn->close();
  91.  
  92. header('location:dane.php');
  93.  
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement