<?php
if (isset($_POST["value"])) {
    $stmt = create_statement("SELECT * FROM comments WHERE name LIKE ? OR parent LIKE ?");
    $params = ["%{$_POST["value"]}%", "%{$_POST["value"]}%"];
    try {
        $stmt->execute($params);
        $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        echo "<p>Failed to insert a new row, dumping details for debug.</p>";
        echo "<p>Incoming \$_POST:<pre>" . print_r($_POST, true) . "</pre>";
        echo "<p>The error code: " . $stmt->errorCode();
        echo "<p>The error message:<pre>" . print_r($stmt->errorInfo(), true) . "</pre>";
        throw $e;
    }
}
?>
<h4>Sök komentarer</h4>
<p>Du kan söka efter författare eller kursmomentsid<br />Ex. Test Testsson eller kmom03.</p>
<form method="post" action="?page=search-comments">
    <input type="text" name="value" placeholder="<?= isset($_POST["value"]) ? $_POST["value"] : "Sök här"; ?>" autofocus><br />
    <input type="submit" value="Sök">
</form>
eller
<form method="post" action="?page=search-comments">
    <input type="hidden" name="value" value="">
    <input type="submit" value="Visa alla">
</form>
<?php echo (isset($res) ? get_comments_table($res) : "");
