[PHP-NOTES] note 130338 added to function.curl-close

[email protected] ("[email protected]")
Newsgroups php.notes
Message-ID <[email protected]>
<?php
$servername = "localhost";
$username = "root";
$password = "";

try {
    $conn = new PDO("mysql:host=$servername;dbname=crud_project", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}

if(isset($_POST['add'])){
    $newTitle = $_POST['title'];
    $newContent = $_POST['content'];
    $stmt = $conn->prepare("INSERT INTO entries (user_id, title, content) VALUES (1, '$newTitle', '$newContent')");
    $stmt->execute();
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

if(isset($_POST['delete'])){
    $delete_id = $_POST['delete'];
    $stmt = $conn->prepare("DELETE FROM entries WHERE id = ?");
    $stmt->execute([$delete_id]);
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

if(isset($_POST['update']) && isset($_POST['title']) && isset($_POST['content'])){
    $stmt = $conn->prepare("UPDATE entries SET title = ?, content = ? WHERE id = ?");
    $stmt->execute([$_POST['title'], $_POST['content'], $_GET['edit']]);
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test Uebung</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col">user_id</th>
            <th scope="col">title</th>
            <th scope="col">content</th>
            <th scope="col">created_at</th>
            <th scope="col">options</th>
        </tr>
        </thead>
        <tbody>
        <?php
        $stmt = $conn->prepare("SELECT * FROM entries");
        $stmt->execute();
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as $row) {
            echo "<tr>";
            foreach ($row as $value) {
                echo "<td>" . $value . "</td>";
            }
            echo "<form method='get'>";
            echo "<td><button class='btn btn-primary' name='edit' value='" . $row['id'] . "'> Details </button></td>";
            echo "</form>";
            echo "<form method='post'>";
            echo "<td><button class='btn btn-danger' name='delete' value='" . $row['id'] . "'> Delete </button></td>";
            echo "</form>";
            echo "</tr>";
        }
        ?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 193.170.70.27)
----
Manual Page -- https://php.net/manual/en/function.curl-close.php
Edit        -- https://main.php.net/note/edit/130338
Del: integrated  -- https://main.php.net/note/delete/130338/integrated
Del: useless     -- https://main.php.net/note/delete/130338/useless
Del: bad code    -- https://main.php.net/note/delete/130338/bad+code
Del: spam        -- https://main.php.net/note/delete/130338/spam
Del: non-english -- https://main.php.net/note/delete/130338/non-english
Del: in docs     -- https://main.php.net/note/delete/130338/in+docs
Del: other reasons-- https://main.php.net/note/delete/130338
Reject      -- https://main.php.net/note/reject/130338
Search      -- https://main.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.