Skip to content

Instantly share code, notes, and snippets.

@aldesantis
Last active April 19, 2016 11:04
Show Gist options
  • Save aldesantis/af975d15a40d8e03173ad1ce4669139a to your computer and use it in GitHub Desktop.
Save aldesantis/af975d15a40d8e03173ad1ce4669139a to your computer and use it in GitHub Desktop.
<?php
$period = isset($_POST['period']) ? trim($_POST['period']) : '';
echo <<<EOF
<form method="post" action="{$_SERVER['REQUEST_URI']}">
<div>
<label for="period">Periodo:</label>
<input type="text" name="period" id="period" value="{$period}">
</div>
<div>
<button type="submit">Invia</button>
</div>
</form>
EOF;
if ('POST' === $_SERVER['REQUEST_METHOD']) {
if ('' === $period) {
echo '<p>Periodo non inserito.</p>';
} else {
try {
$pdo = new \PDO('mysql:host=localhost;dbname=database', 'user', 'pass');
} catch (\PDOException $e) {
die($e->getMessage());
}
$stm = $pdo->prepare('SELECT * FROM elements WHERE period = ?');
try {
$stm->execute($period);
} catch (\PDOException $e) {
die($e->getMessage());
}
echo <<<EOF
<table>
<thead>
<tr>
<th>Numero</th>
<th>Nome</th>
<th>Gruppo</th>
<th>Periodo</th>
</tr>
</thead>
<tbody>
EOF;
while ($row = $stm->fetchAssoc()) {
echo <<<EOF
<tr>
<td>{$row['number']}</td>
<td>{$row['name']}</td>
<td>{$row['group']}</td>
<td>{$row['period']}</td>
</tr>
EOF;
}
echo <<<EOF
</tbody>
</table>
EOF;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment