function muuda(){ if (!isset($_SESSION['user']) || $_SESSION['roll'] != 'admin') { include_once('views/login.html'); } else { $errors=array(); if (!empty($_POST)){ if (empty($_POST["id"])) { kuva_puurid(); } else { $id = $_POST["id"]; } if (empty($_POST["nimi"])) { $errors[]="nimi kohustuslik"; } if (empty($_POST["puur"])) { $errors[]="puur kohustuslik"; } if (empty($errors)){ global $connection; $nimi=mysqli_real_escape_string($connection, $_POST["nimi"]); $puur=mysqli_real_escape_string($connection, $_POST["puur"]); $liik=mysqli_real_escape_string($connection, $_FILES["liik"]["name"]); $id= mysqli_real_escape_string($connection, $_POST["id"]); $sql = "UPDATE 10153316_loomaaed SET nimi='$nimi', puur='$puur' WHERE id = '$id'"; $result = mysqli_query($connection, $sql); var_dump(mysqli_error($connection)); if (!$result) { echo "Pildi muutmine ebaõnnestus."; } else { if (!empty($_FILES["liik"]["name"])) { $sql = "UPDATE 10153316_loomaaed SET liik='pildid/".$liik."' WHERE id = '$id'"; $result = mysqli_query($connection, $sql); kuva_puurid(); } } include_once('views/editvorm.html'); } } include_once('views/editvorm.html'); } }
require_once 'funk.php'; session_start(); connect_db(); $page = "pealeht"; if (isset($_GET['page']) && $_GET['page'] != "") { $page = htmlspecialchars($_GET['page']); } include_once 'views/head.html'; switch ($page) { case "login": logi(); break; case "loomad": if (isset($_SESSION['user'])) { kuva_puurid(); } else { header("Location: ?page=login"); exit(0); } break; case "logout": logout(); break; case "lisa": if (isset($_SESSION['user'])) { lisa(); } else { header("Location: ?page=login"); exit(0); }
function muuda() { global $connection; $errors = array(); if (!isset($_SESSION['user']) || $_SESSION['roll'] != 'admin') { header("Location: ?page=login"); } if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['id']) && $_GET['id'] != "") { $id = $_GET['id']; $loom = hangi_loom(mysqli_real_escape_string($connection, $id)); } else { header("Location: ?page=loomad"); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['muuda'])) { if (empty($_POST['nimi'])) { $errors['no_name'] = "Sisesta nimi!"; } if (empty($_POST['puur'])) { $errors['no_cage'] = "Sisesta puuri number!"; } if (empty($_FILES['liik']['name'])) { $errors['no_picture'] = "Sisesta pilt!"; } $nimi = mysqli_real_escape_string($connection, $_POST['nimi']); $puur = mysqli_real_escape_string($connection, $_POST['puur']); $liik = mysqli_real_escape_string($connection, $_FILES['liik']['name']); $lisa_loom = "INSERT INTO audusaar_loomaaed (nimi, liik, puur) VALUES ('{$nimi}', 'pildid/" . $liik . "', '{$puur}')"; echo mysqli_insert_id($connection); $result = mysqli_query($connection, $lisa_loom); if (!$result) { echo "Pildi üleslaadimine ebaõnnestus."; } else { kuva_puurid(); } include_once 'views/editform.html'; } include_once 'views/editform.html'; }