php pdo get id selected by href

Solutions on MaxInterview for php pdo get id selected by href by the best coders in the world

showing results for - "php pdo get id selected by href"
Camilla
23 Jul 2020
1<?php
2include "/includes/db.php";
3$id = $_GET['id'];
4$options = [
5    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,        // enable PDO errors
6    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,   // fetch associative arrays by default
7    PDO::ATTR_EMULATE_PREPARES => false,                // Use native prepared statements
8];
9//                      You should always specify charset VVVVV
10$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password, $options);
11
12// Prepare and execute SQL passing in the value of $id  // Verificar o pedido "GET" id param
13  $id = $_GET['id'];
14  
15  // Preparar e executar a passagem SQL no valor de $id
16  $query = $pdo->prepare('SELECT * FROM nametable WHERE id = ? ORDER BY nameselect DESC');
17  $query->execute([$id]);
18?>
19  <html>
20   <?php foreach($query as $row ?>
21     $row  ['namerow']
22     <?php } ?>
23  </html>