php pdo get id selected by href

112

<?php
include "/includes/db.php";
$id = $_GET['id'];
$options = [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,        // enable PDO errors
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,   // fetch associative arrays by default
    PDO::ATTR_EMULATE_PREPARES => false,                // Use native prepared statements
];
//                      You should always specify charset VVVVV
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password, $options);

// Prepare and execute SQL passing in the value of $id  // Verificar o pedido "GET" id param
  $id = $_GET['id'];
  
  // Preparar e executar a passagem SQL no valor de $id
  $query = $pdo->prepare('SELECT * FROM nametable WHERE id = ? ORDER BY nameselect DESC');
  $query->execute([$id]);
?>
  <html>
   <?php foreach($query as $row ?>
     $row  ['namerow']
     <?php } ?>
  </html>

Comments

Submit
0 Comments