O clássico
Essa você já conhece, né?
<!-- Arquivo: index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Find user | TestSite</title>
<meta charset="utf-8" />
</head>
<body lang="en-US">
<h1>Find users</h1>
<form method="GET" action="./user.php">
<p>
<label for="email">E-mail:</label>
<input
type="text"
id="email"
name="email"
placehoder="user@example.com"
/>
</p>
<input type="submit" value="Open profile" />
</form>
</body>
</html>
<?php
// Arquivo: user.php
$dbHost = getenv('DB_HOST');
$dbName = getenv('DB_NAME');
$dbUser = getenv('DB_USER');
$dbPass = getenv('DB_PASS');
$dbCharset = getenv('DB_CHARSET') ?: 'utf8mb4';
try {
$pdo = new PDO(
"mysql:host=$dbHost;dbname=$dbName;charset=$dbCharset",
$dbUser,
$dbPass,
;
)
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$email = $_GET['email'];
$sql = "
SELECT
email,
name
FROM users
WHERE
email = '$email'
";
$statement = $pdo->prepare($sql);
$statement->execute();
$users = $statement->fetchAll(PDO::FETCH_ASSOC);
catch (\Throwable $e) {
} throw $e;
echo "Something went wrong!";
http_response_code(500);
return;
}
foreach ($users as $user) {
echo "Name: {$user['name']} | E-mail: {$user['email']}<br />";
}