<?php
include('includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>What is your favorite book?</h1>');
// Note the variables being passed via the GET ternary operators.
$step = isset($_GET['step']) ? $_GET['step'] : 0;
$title = isset($_GET['title']) ? $_GET['title'] : '';
$author = isset($_GET['author']) ? $_GET['author'] : '';
$series = isset($_GET['series']) ? $_GET['series'] : '';
$published = isset($_GET['published']) ? $_GET['published'] : '';
$length = isset($_GET['length']) ? $_GET['length'] : '';
// filter all input taken from the Browser
$step = htmlentities($step);
$title = htmlentities($title);
$author = htmlentities($author);
$series = htmlentities($series);
$published = htmlentities($published);
$length = htmlentities($length);
if ($step == 0) // first time into this form
{
?>
<form action="book-array.php" method="GET" class="pad">
<label for="title">Book Title</label>
<input type="text" size="36" id="title" name="title" value="">
<br><br>
<label for="author">Book Author</label>
<input type="text" size="36" id="author" name="author" value="">
<br><br>
<label for="series">Series? y/n</label>
<input type="text" size="36" id="series" name="series" value="">
<br><br>
<label for="published">Year Published</label>
<input type="number" size="36" id="published" name="published" value="">
<br><br>
<label for="length">Series Length</label>
<input type="number" size="36" id="length" name="length" value="">
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
</form>
<?php
} else // Puts the user number inputs in an array, then sorts that array and prints it.
{
$book = array
(
array
(
'title' => "$title",
'author' => "$author",
'series' => "$series",
'published' => "$published",
'length' => "$length",
)
);
echo '<pre>'; print_r($book); echo '</pre>';
}
// provides a form to try again
if (!$step == 0){
?>
<form action="book-array.php" method="GET">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('includes/footer.php');
?>