Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4.  
  5. //DODAWANIE
  6.  
  7.  
  8. if (isset($_POST['dodaj'])) {
  9. $cena = $_POST['cena'];
  10. $nazwa = $_POST['nazwa'];
  11. $link = $_POST['link'];
  12. require_once "connect.php";
  13. $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
  14. if ($polaczenie->connect_errno!=0) {
  15. echo "Error: ".$polaczenie_errno;
  16. } else {
  17. if ($polaczenie->query("INSERT INTO kwiatki VALUES (NULL, '$nazwa', '$cena', '$link')")) {
  18. header('Location: index.php');
  19. }
  20. }
  21. }
  22.  
  23.  
  24. //USUWANIE
  25.  
  26.  
  27. if (isset($_POST['usun'])) {
  28. require_once "connect.php";
  29. $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
  30. if ($polaczenie->connect_errno!=0) {
  31. echo "Error: ".$polaczenie_errno;
  32. } else {
  33. $id = $_POST['id'];
  34. if ($polaczenie->query("DELETE FROM kwiatki WHERE id=$id")) {
  35. header('Location: index.php');
  36. }
  37. }
  38. }
  39.  
  40.  
  41. //EDYTOWANIE
  42.  
  43.  
  44.  
  45. if (isset($_POST['edytuj'])) {
  46. require_once "connect.php";
  47. $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
  48. if ($polaczenie->connect_errno!=0) {
  49. echo "Error: ".$polaczenie_errno;
  50. } else {
  51. $nazwa = $_POST['nazwa'];
  52. $cena = $_POST['cena'];
  53. $url = $_POST['link'];
  54. $id = $_POST['id'];
  55. if ($polaczenie->query("UPDATE kwiatki SET nazwa='$nazwa', cena='$cena', obraz='$url' WHERE id='$id'")) {
  56. header('Location: index.php');
  57. }
  58. }
  59. }
  60. ?>
  61. <!DOCTYPE html>
  62. <html>
  63. <head>
  64. <meta charset="utf-8">
  65. <title>Stroga główna</title>
  66. <link rel="stylesheet" type="text/css" href="style.css">
  67. <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  68. <style type="text/css">
  69. #edytuj {float:left; background-image: url(img/bg2.png); width: 333px; min-height: 500px;}
  70. .edytuj-upper {min-height: 50px; background: rgba(156,39,176, 0.7); padding-bottom: 5px;}
  71. .edytuj-top {min-height: 50px; background: rgba(156,39,176, 0.3); padding-top: 20px}
  72. .edytuj-mid {min-height: 50px; background: rgba(156,39,176, 0.3); padding-top: 20px}
  73. .edytuj-bot {min-height: 50px; background: rgba(156,39,176, 0.3); padding-top: 20px}
  74. .edytuj-bottom {min-height: 50px;background: rgba(156,39,176, 0.3); padding-top: 10px}
  75. </style>
  76. </head>
  77. <body><center>
  78. <div id="container" style="width: 1500px">
  79. <div id="header"><h1>Kwiatki Baza Danych</h1></div>
  80. <div id="left">
  81. <div class="left-top">
  82. <h1>Baza Danych</h1>
  83. </div>
  84. <div class='left-middle'>
  85. <div class='left-middle-top'>
  86. <div class="left-middle-top-1">ID</div>
  87. <div class="left-middle-top-2">Nazwa</div>
  88. <div class="left-middle-top-3">Cena</div>
  89. <div class="left-middle-top-4">Obrazek</div>
  90. <div style="clear:both"></div>
  91. </div>
  92. <?php
  93.  
  94.  
  95. //WYŚWIETLANIE
  96.  
  97.  
  98. require_once "connect.php";
  99. $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
  100. if ($polaczenie->connect_errno!=0) {
  101. echo "Error: ".$polaczenie_errno;
  102. } else {
  103. if ($rezultat = @$polaczenie->query(sprintf("SELECT * FROM kwiatki"))) {
  104. $ile_kwiatkow=$rezultat->num_rows;
  105. if($ile_kwiatkow>0) {
  106. while($wiersz = $rezultat->fetch_assoc()) {
  107. echo "<div class='left-middle-bot>";
  108. echo "<div class='left-middle-bot-1'>".$wiersz['id']."</div>";
  109. echo "<div class='left-middle-bot-2'>".$wiersz['nazwa']."</div>";
  110. echo "<div class='left-middle-bot-3'>".$wiersz['cena']." zł</div>";
  111. echo "<div class='left-middle-bot-3'><a href=".$wiersz['obraz']." target='_blank'><img src=".$wiersz['obraz']."></a></div>";
  112. echo "<div style='clear:both'></div>";
  113. echo "</div>";
  114. echo "<a<p><button type='submit' name='usun' class='w3-button w3-block w3-red'>Usuń</button>";
  115. echo "<p><button type='submit' name='edytuj' class='w3-button w3-block w3-purple'>Edytuj</button></p>";
  116. }
  117. }
  118. }
  119. }
  120. ?>
  121. </div>
  122. </div>
  123. <div id="middle">
  124. <div class="middle-upper">
  125. <h1>Dodaj do bazy</h1>
  126. </div>
  127. <form method="post">
  128. <div class="middle-top">Nazwa <input type="text" name="nazwa"></div>
  129. <div class="middle-mid">Cena <input type="number" name="cena"></div>
  130. <div class="middle-bot">URL <input type="text" name="link"></div>
  131. <div class="middle-bottom"><p><button type="submit" name="dodaj" class="w3-button w3-block w3-teal">Dodaj</button></p></div>
  132. </form>
  133. </div>
  134. </div></center>
  135. </body>
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement