I found Google documentation pretty helpful and in my opinion doesn’t dump you off in the deep end of the pool. I would suggest keeping most of your PHP at the top end of the page. I wrote a simple search using the world database that you can find at php.net (another good source for help). You HTML between your tags are incorrect take a look at mine to get a better idea how to do it.
[php]<?php
include ‘lib/includes/connect/connect.php’;
$db_options = [
/* important! use actual prepared statements (default: emulate prepared statements) /
PDO::ATTR_EMULATE_PREPARES => false
/ throw exceptions on errors (default: stay silent) /
, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
/ fetch associative arrays (default: mixed arrays) */
, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
];
if (filter_input(INPUT_POST, submit)) {
$pdo = new PDO('mysql:host=' . DATABASE_HOST . ';dbname=world;charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD, $db_options);
$query = 'SELECT Name, CountryCode, District, Population FROM city WHERE CountryCode=:CountryCode ORDER BY District'; // Set the Search Query:
$stmt = $pdo->prepare($query); // Prepare the query:
$result = $stmt->execute([':CountryCode' => filter_input(INPUT_POST, countryCode)]); // Execute the query with the supplied user's parameter(s):
}
?>
Database Search
search
>
City |
Country Code |
District / State |
Population |
<?php
if ($result) {
while ($record = $stmt->fetch()) {
echo "";
echo '' . $record->Name . " | ";
echo '' . $record->CountryCode . " | ";
echo '' . $record->District . " | ";
echo '' . $record->Population . " | ";
echo "
";
}
}
?>
</body>
[/php]
It uses PHP 7 but with a few minor version it would run on lower versions. I would also look over Google’s documentation once again and maybe looking over my code to get a GENERAL idea on how to make work? Maybe someone else here will have a better idea?