[PHP-NOTES] note 130306 added to language.basic-syntax

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

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

$stmt = $conn->query("SELECT * FROM customers");

if(isset($_GET['id'])) {
    $del = $_GET['id'];
    $stmt = $conn->query("DELETE FROM customers WHERE customerNumber = :del");
}

if(!empty($_GET['search'])) {
$sr = $_GET['search'];
$stmt = $conn->query("SELECT * FROM customers WHERE title LIKE '$sr%'");
}

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Titel</title>
</head>
<body>

    <form action="lernen.php" method="get">
        <input type="text" name="search" placeholder="Suchen...">
        <input type="submit">   
    </form>

    <table> 
        <thead>
            <tr>
                <th href="lernen.php?title=true">Title</th>
                <th href="lernen.php?author=true">Autor</th>
                <th href="lernen.php?publish_date=true">Veröffentlicht</th>
                <th href="lernen.php?comments=true">Kommentare</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($result as $row){
                echo "<tr>";
                    echo "<td>". $row['title']. "</td>";
                    echo "<td>". $row['author']. "</td>";
                    echo "<td>". $row['publish_date']. "</td>";
                    echo "<td>". $row['comments']. "</td>";

                    echo "<td> <a href='lernen.php?id=" . $row['title'] . "'>Löschen</a></td>";
                    echo "<td><input type='checkbox' name='del[]' value='". $row['title']. "'></td>";
                    echo "<td><a href='lernen.php?edit" = . $row['title'] . "'>Bearbeiten</td>";
                echo "</tr>";
            }
            ?>
        </tbody>
    </table>

</body>
</html>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 193.170.70.27)
----
Manual Page -- https://php.net/manual/en/language.basic-syntax.php
Edit        -- https://main.php.net/note/edit/130306
Del: integrated  -- https://main.php.net/note/delete/130306/integrated
Del: useless     -- https://main.php.net/note/delete/130306/useless
Del: bad code    -- https://main.php.net/note/delete/130306/bad+code
Del: spam        -- https://main.php.net/note/delete/130306/spam
Del: non-english -- https://main.php.net/note/delete/130306/non-english
Del: in docs     -- https://main.php.net/note/delete/130306/in+docs
Del: other reasons-- https://main.php.net/note/delete/130306
Reject      -- https://main.php.net/note/reject/130306
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.