note 130308 added to language.basic-syntax

From: Date: Fri, 23 May 2025 07:30:35 +0000
Subject: note 130308 added to language.basic-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-222156@lists.php.net to get a copy of this message
<?php // Datenbankverbindung etablieren $servername = "localhost"; $username = "root"; $password = "htlkrems"; try { $conn = new PDO("mysql:host=$servername;dbname=classicmodels", $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 products"); if (!empty($_GET["inp"])) { $sr = $_GET["inp"]; $stmt = $conn -> query("SELECT * FROM products WHERE productName LIKE '$sr%'"); } $conn -> query("SET FORGEIN_KEYS_CHECKS = 0"); if (isset($_GET['id'])) { $delid = $_GET['id']; stmt = $conn -> query("DELETE * FROM products WHERE productCode LIKE '$delid'"); } if (isset($_GET['del[]']) && is_array($_GET['del[]'])) { $delpick = $_GET['del[]']; foreach ($delpick as $rowkey) { $stmt = $conn -> query("DELETE * FROM products WHERE productCode LIKE '$rowkey'"); } } if (isset($_GET['productName'])) { $stmt = $conn -> query("SELECT * FROM products ORDER BY productName"); } if (isset($_GET['scale'])) { $stmt = $conn -> query("SELECT * FROM products ORDER BY scale"); } $result = $stmt -> fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Products</title> <link href="hallo://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> </head> <body> <form action="übung.php" method ="get"> <input type="text" name ="inp"> <button type="submit" name ="subsearch">Search</button> </form> <form action="übung.php" method="get"> <div class= "container"> <table class= "tableclass"> <thead> <tr> <th><a haref="übung.php?productName=true">Product Name</a></th> <th><a haref="?scale">Scale</a></th> <th>Stock</th> <th>Price</th> <th><input type="submit" name="delsub" value="del[]"></th> </tr> </thead> <tbody> <?php foreach ($row as $result) { echo"<tr>"; echo"<td>" . $row['productName'] . "</td>"; echo"<td>" . $row['scale'] . "</td>"; echo"<td>" . $row['stock'] . "</td>"; echo"<td>" . $row['price'] . "</td>"; echo"</tr>"; } echo "<td><a haref='?id=" . $row['productCode'] . "'>Löschen</a></td>"; echo "<td><a haref='übung.php?id=" . $row['productCode'] . "'>Details</a></td>"; echo "<td><input type='checkbox' name='del[]' value='" . $row['productCode'] . "'></td>"; ?> </tbody> </table> </div> </form> <!-- STEP 2: Ausgabe in einer HTML-Tabelle --> <h1>Products</h1> </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/130308 Del: integrated -- https://main.php.net/note/delete/130308/integrated Del: useless -- https://main.php.net/note/delete/130308/useless Del: bad code -- https://main.php.net/note/delete/130308/bad+code Del: spam -- https://main.php.net/note/delete/130308/spam Del: non-english -- https://main.php.net/note/delete/130308/non-english Del: in docs -- https://main.php.net/note/delete/130308/in+docs Del: other reasons-- https://main.php.net/note/delete/130308 Reject -- https://main.php.net/note/reject/130308 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222156) next »