aboutsummaryrefslogtreecommitdiff
path: root/bug/update.php
blob: f27cdd4b39c274bc25aa642fe00bc40b62bbc2df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require 'config.php';
require_once(TEMPLATES_PATH . "/header.php");
require_once(TEMPLATES_PATH . "/panel.php");
require_once(LIBRARY_PATH . "/functions.php");

if(!isset($_GET['id']) || $_GET['id'] == "") {
    echo "<div id='error'>No bug selected, redirecting to index...</div>";
    header('Refresh: 2; URL=index.php');

} else if(!isset($_SESSION['user_id']) || $_SESSION['user_id'] == "") {
    echo "<div id='error'>Not logged in, redirecting to index...</div>";
    header('Refresh: 2; URL=index.php');

} else {
    $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->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";
    }

    header("Refresh: 2; URL=view.php?id=$_GET[id]");

}

require_once(TEMPLATES_PATH . "/footer.php");
?>