Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- //DODAWANIE
- if (isset($_POST['dodaj'])) {
- $cena = $_POST['cena'];
- $nazwa = $_POST['nazwa'];
- $link = $_POST['link'];
- require_once "connect.php";
- $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
- if ($polaczenie->connect_errno!=0) {
- echo "Error: ".$polaczenie_errno;
- } else {
- if ($polaczenie->query("INSERT INTO kwiatki VALUES (NULL, '$nazwa', '$cena', '$link')")) {
- header('Location: index.php');
- }
- }
- }
- //USUWANIE
- if (isset($_POST['usun'])) {
- require_once "connect.php";
- $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
- if ($polaczenie->connect_errno!=0) {
- echo "Error: ".$polaczenie_errno;
- } else {
- $id = $_POST['id'];
- if ($polaczenie->query("DELETE FROM kwiatki WHERE id=$id")) {
- header('Location: index.php');
- }
- }
- }
- //EDYTOWANIE
- if (isset($_POST['edytuj'])) {
- require_once "connect.php";
- $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
- if ($polaczenie->connect_errno!=0) {
- echo "Error: ".$polaczenie_errno;
- } else {
- $nazwa = $_POST['nazwa'];
- $cena = $_POST['cena'];
- $url = $_POST['link'];
- $id = $_POST['id'];
- if ($polaczenie->query("UPDATE kwiatki SET nazwa='$nazwa', cena='$cena', obraz='$url' WHERE id='$id'")) {
- header('Location: index.php');
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Stroga główna</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
- <style type="text/css">
- #edytuj {float:left; background-image: url(img/bg2.png); width: 333px; min-height: 500px;}
- .edytuj-upper {min-height: 50px; background: rgba(156,39,176, 0.7); padding-bottom: 5px;}
- .edytuj-top {min-height: 50px; background: rgba(156,39,176, 0.3); padding-top: 20px}
- .edytuj-mid {min-height: 50px; background: rgba(156,39,176, 0.3); padding-top: 20px}
- .edytuj-bot {min-height: 50px; background: rgba(156,39,176, 0.3); padding-top: 20px}
- .edytuj-bottom {min-height: 50px;background: rgba(156,39,176, 0.3); padding-top: 10px}
- </style>
- </head>
- <body><center>
- <div id="container" style="width: 1500px">
- <div id="header"><h1>Kwiatki Baza Danych</h1></div>
- <div id="left">
- <div class="left-top">
- <h1>Baza Danych</h1>
- </div>
- <div class='left-middle'>
- <div class='left-middle-top'>
- <div class="left-middle-top-1">ID</div>
- <div class="left-middle-top-2">Nazwa</div>
- <div class="left-middle-top-3">Cena</div>
- <div class="left-middle-top-4">Obrazek</div>
- <div style="clear:both"></div>
- </div>
- <?php
- //WYŚWIETLANIE
- require_once "connect.php";
- $polaczenie = @new mysqli ($host, $db_user, $db_password, $db_name);
- if ($polaczenie->connect_errno!=0) {
- echo "Error: ".$polaczenie_errno;
- } else {
- if ($rezultat = @$polaczenie->query(sprintf("SELECT * FROM kwiatki"))) {
- $ile_kwiatkow=$rezultat->num_rows;
- if($ile_kwiatkow>0) {
- while($wiersz = $rezultat->fetch_assoc()) {
- echo "<div class='left-middle-bot>";
- echo "<div class='left-middle-bot-1'>".$wiersz['id']."</div>";
- echo "<div class='left-middle-bot-2'>".$wiersz['nazwa']."</div>";
- echo "<div class='left-middle-bot-3'>".$wiersz['cena']." zł</div>";
- echo "<div class='left-middle-bot-3'><a href=".$wiersz['obraz']." target='_blank'><img src=".$wiersz['obraz']."></a></div>";
- echo "<div style='clear:both'></div>";
- echo "</div>";
- echo "<a<p><button type='submit' name='usun' class='w3-button w3-block w3-red'>Usuń</button>";
- echo "<p><button type='submit' name='edytuj' class='w3-button w3-block w3-purple'>Edytuj</button></p>";
- }
- }
- }
- }
- ?>
- </div>
- </div>
- <div id="middle">
- <div class="middle-upper">
- <h1>Dodaj do bazy</h1>
- </div>
- <form method="post">
- <div class="middle-top">Nazwa <input type="text" name="nazwa"></div>
- <div class="middle-mid">Cena <input type="number" name="cena"></div>
- <div class="middle-bot">URL <input type="text" name="link"></div>
- <div class="middle-bottom"><p><button type="submit" name="dodaj" class="w3-button w3-block w3-teal">Dodaj</button></p></div>
- </form>
- </div>
- </div></center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement