I am attempting to convert my code to use PDO, but am running into issues when trying to display the results from a query constructed from a webform. I have obviously done something wrong as no results are displayed. Any help would be appreciate it. I assume it has something to do with the prepared statements.
Here is my main form.php page, where I have the user input the hostname value to be used in my query-
[php]
Here is the main php where I make the connection to the database, run the query and try to display the results.
[php]<?php
$hostname = $_POST[ ‘hostname’];
$user = ‘public’;
$pass = ‘’;
$db = new PDO (‘mysql:host=localhost;dbname=Inventory’, $user, $pass );
$sql= “SELECT * FROM serverlist WHERE hostname = :hostname”;
$stmt = $pdo->prepare($sql);
$stmt->bindParam(’:hostname’, $hostname, PDO::PARAM_STR);
$stmt->execute();
while ($row = $stmt->fetchObject()) {
echo $row->hostname;
}
?>[/php]