Commit 4dff362c authored by Sorrel Harriet's avatar Sorrel Harriet

initial work on week 6 material

parent 549ae60e
......@@ -3,5 +3,6 @@
<li><a href="?page=home" title="home">Home</a></li>
<li><a href="?page=record" title="records">Records</a></li>
<li><a href="?page=orders" title="orders">Orders</a></li>
<li><a href="?page=add-record" title="add record">Add record</a></li>
</ul>
</nav>
<?php
/* define a variable with path to script which will handle submission
$_SERVER["PHP_SELF"] is a path to the current script
htmlspecialchars() is used to escape HTML characters (prevents XSS) */
$action = htmlspecialchars($_SERVER["PHP_SELF"]);
// fetch the artists so that we have access to the ids
$sql = "SELECT id, first_name, last_name
FROM artist";
$result = mysqli_query($link, $sql);
// check query returned a result
if ($result === false) {
echo mysqli_error($link);
} else {
$options = "";
// create an option for each artist
while ($row = mysqli_fetch_assoc($result)) {
$options .= "<option value='".$row['id']."'>";
$options .= $row['first_name']." ".$row['last_name'];
$options .= "</option>";
}
}
// define the form HTML (would ideally be in a template)
$form_html = "<form action='".$action."' method='POST'>
<fieldset>
<label for='artist_id'>Artist:</label>
<select name='artist_id'>
<option value='NULL'>Not listed</option>
".$options."
</select>
</fieldset>
<fieldset>
<label for='title'>Title:</label>
<input type='text' name='title' />
</fieldset>
<fieldset>
<label for='price'>Price (&pound;):</label>
<input type='text' name='price' />
</fieldset>
<fieldset>
<label for='genre'>Genre</label>
<input type='text' name='genre' />
</fieldset>
<button type='submit'>Submit</button>
</form>";
?>
......@@ -2,6 +2,7 @@
// create variable for content HTML
$content = "<h1>Records</h1>";
$content .= "<p>You are now viewing all records in the database.</p>";
// fetch records as a result set
$sql = "SELECT r.title, a.first_name, a.last_name, r.genre, r.price, a.id
......@@ -15,7 +16,9 @@ $result = mysqli_query($link, $sql);
if ($result === false) {
echo mysqli_error($link);
} else {
$content .= "<table border='1'><tbody>";
$content .= "<table border='1'>";
$content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th></tr></thead>";
$content .= "<tbody>";
// fetch associative array
while ($row = mysqli_fetch_assoc($result)) {
$content .= "<tr>";
......@@ -33,7 +36,4 @@ if ($result === false) {
// output the content HTML
echo $content;
// include the search form
include('templates/search-form.html');
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment