aircraft-dev-registry/www/index.php
fly ff3d23195a Initial Commit
Signed-off-by: fly <merspieler@airmail.cc>
2021-06-03 22:24:25 +02:00

45 lines
1.3 KiB
PHP

<html>
<head>
<title>Aircraft Developer Registry</title>
</head>
<body>
<h1>Aircraft Developer Registry</h1>
<h2>Sign Up</h2>
<form action="signup.php" method="POST">
<label>Aircraft ID</label><input type="text" name="aircraft-id" required/><br/>
<label>Email Address</label><input type="email" name="email" required/><br/>
<input type="hidden" name="name"/>
<input type="submit" value="Sign Up"/>
</form><br/>
<h2>Statistics</h2>
<?php
$con = new mysqli(getenv("SQL_HOST"), getenv("SQL_USER"), getenv("SQL_PASSWORD"), getenv("SQL_DATABASE"), getenv("SQL_PORT"));
$fetch_failed = false;
if ($con->connect_error)
{
$fetch_failed = true;
}
else
{
// Aircraft stats
echo('<table border="1"><tr><th>Aircraft</th><th>Developers</th></tr>');
$sql = "SELECT acid, COUNT(user) AS ucount FROM `aircraft-devs` GROUP BY acid;";
$result = $con->query($sql);
while ($row = $result->fetch_assoc())
{
echo('<tr><td>' . $row["acid"] . '</td><td>' . $row["ucount"] . '</td></tr>');
}
echo('</table><br/>');
// User stats
$sql = "SELECT COUNT(DISTINCT user) AS ucount FROM `aircraft-devs`;";
$result = $con->query($sql);
$row = $result->fetch_assoc();
echo('There are ' . $row["ucount"] . ' developers registered');
}
if ($fetch_failed)
{
echo("Unable to get complete statistics");
}
?>
</body>
</html>