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

[email protected] ("[email protected]")
Newsgroups php.notes
Message-ID <[email protected]>
<?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/[email protected]/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
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.