I've got a php project connected to a local database where I've created a form where users can search for a book based on it's subject. When the user presses search, the information should be posted to another php page within my project and the filtered information shown within a table.
However, although there are no syntax errors, the variables are not being passed. The page is blank.
I was wondering if anyone could look over my code and help me with any suggestions? I'm fairly new to php (6 months) and it's frustrating my greatly.
thanks.
index 1st page.php
Code: Select all
<?php
$db = new mysqli ('localhost','root','','library');
$results = $db->query('select distinct subject from catalogue order by subject');
?>
<form action="view.php?library" method="POST">
<select name="library">
<option>All Subjects</option>
<?php while ($row = $results->fetch_assoc()){?>
<option><?php echo $row['subject']?></option>
<?php }?>
<input name="library" input type="submit" value="search" />
</select>
</form>
<?php
$db->close();
?>view page.php
Code: Select all
<?php
$library = $_POST['library'];
$db = new mysqli ('localhost','root','','library');
$sql = "select author, title, description from catalogue where subject = '{$_POST['library']}' order by title";
$results = $db->query($sql);
?>
<table border="3" cellpadding="8">
<?php while($row = $results->fetch_array(MYSQLI_ASSOC)){ ?>
<tr>
<td width="300px" border="1"><?php echo $row['author'] ?></td>
<td width="300px" border="1"><?php echo $row['title'] ?></td>
</tr>
<tr><td width="500px" border="1"><?php echo $row['description'] ?></td></tr>
<?php } ?>
</table>
<?php $db->close(); ?>
Thanks again!