CSS PHP Forms with MySQL query
Use the following to ask for a value in a form and then query a database and display the results formated with CSS from a stylesheet.
Contents of lookup.php
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
<?php include 'stylesheet.php'; ?>
</style>
<div class="container">
<img src="ageloc-me.jpg">
<div class="label">Enter code:</div>
</div>
<?php
$con=mysqli_connect("localhost","user","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM test");
<tr>
<th>code</th>
<th>name</th>
<th>age</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['code'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Contents of stylesheet.php
table {
border-collapse: collapse;
}
table, th, td {
padding: 10px;
border: 1px solid black;
}
.container {
position: relative;
text-align: center;
color: white;
}
.bottom-left {
position: absolute;
bottom: 8px;
left: 16px;
}
.label {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}