From cf270f3726a8037ebef80888eb510172688e13a7 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 30 Apr 2021 09:35:40 +0300 Subject: CRUD bugs --- bug/update.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'bug/update.php') diff --git a/bug/update.php b/bug/update.php index f27cdd4..0ee6e26 100644 --- a/bug/update.php +++ b/bug/update.php @@ -1,35 +1,30 @@ No bug selected, redirecting to index..."; - header('Refresh: 2; URL=index.php'); - -} else if(!isset($_SESSION['user_id']) || $_SESSION['user_id'] == "") { - echo "
Not logged in, redirecting to index...
"; - header('Refresh: 2; URL=index.php'); - -} else { +if(session_set()) { $conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']); - - $query = $conn->prepare("UPDATE bugs SET title=:title, description=:description WHERE id=:id"); + $query = $_POST['id'] == "" ? + $conn->prepare("INSERT INTO bugs (author, title, description) VALUES (:user_id, :title, :description)") + : $conn->prepare("UPDATE bugs SET title=:title, description=:description WHERE id=:bug_id"); + if($_POST['id'] == "") { + $query->bindParam(':user_id', $_SESSION['user_id']); + } else { + $query->bindParam(':bug_id', $_POST['id']); + } $query->bindParam(':title', $_POST['title']); $query->bindParam(':description', $_POST['description']); - $query->bindParam(':id', $_GET['id']); if ($query->execute()) { echo "Data is updated\n"; } else { - echo "User must have sent wrong inputs\n"; + echo "Query failed\n"; } - - header("Refresh: 2; URL=view.php?id=$_GET[id]"); - } -require_once(TEMPLATES_PATH . "/footer.php"); +header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]"); +footer: require_once(TEMPLATES_PATH . "/footer.php"); ?> -- cgit v1.2.1