Show sourcecode

The following files exists in this folder. Click to view.

test/incl/blokket2/

add-article.php
aside.php
blokket-default.php
data/
initiate.php
remove-article.php
show-all-articles.php
show-article.php
update-article.php
update-article_backup.php

remove-article.php

1 lines ASCII Unix (LF)
1
<?php
$db = new PDO("sqlite:incl/blokket2/data/ads");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); // Display errors, but continue script.

$path = "incl/blokket/data/";
$selected = "- Select article -";
$removed = null;

if(isset($_POST['doRemove']) && $_POST['article-selection'] != "- Select article -")
{
    $stmt = $db->prepare("DELETE FROM Ads WHERE id=?");
    $id = $_POST['article-selection'];
    $stmt->bindParam(1, $id, PDO::PARAM_STR);
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    $removed = true;
}
?>

<h1>Remove article</h1>
<fieldset>
    <form method="post">
        <p><label for="article-selection">Available articles:</label><br>
        <select id="article-selection" name="article-selection">
            <?php
            $stmt = $db->prepare('SELECT * FROM Ads;');
            $stmt->execute();
            $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
            echo "<option value='" . "- Select article -" . "' selected>" . "- Select article -" . "</option>";
            $options = "";
            foreach ($rows as $row)
            {
                if ($selected == $row['id'])
                    $options .= "<option value='" . $row['id'] . "' selected>" . $row['title'] . "</option>";
                else
                    $options .= "<option value='" . $row['id'] . "'>" . $row['title'] . "</option>";
            }
            echo $options;
            ?>
        </select>
        </p>
        <p><input type="submit" name="doRemove" value="Remove article"></p>
    </form>
    <?php if($removed == true): ?>
        <p class="success">The article was removed.</p>
    <?php endif; ?>
</fieldset>