bradgrafelman;10949288 wrote:After the if() statement halojoy suggested, try adding this:
echo "\n<!-- # of rows found: " . mysqli_num_rows($result) . "-->\n";
Then, view the HTML source of the page in your browser. Do you see the comment? If so, how many rows does it say were found? Is there anything else between the <select>..</select> tags?
Okay I put that in as well so now my code looks like this:
<?php
//This page allows the administrator to add a book.
// Sets the page title and includes the PHP header.
$page_title = 'Add Book';
include ('./includes/header.php');
if (isset($_POST['submitted'])) { // Check if the form has been submitted.
require_once ('/mysqli_connect.php'); // Connect to the database.
} else { // Display the form.
?>
<form enctype="multipart/form-data" action="test.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="524288">
<fieldset><legend>Fill out the form to add a book to the catalog:</legend>
<p><b>Author:</b>
<p><input type="radio" name="author" value="existing" /> Existing
<select name="existing"><option>Select One</option>
<?php
// Retrieve all the artists and add to the pull-down menu.
// we put single quotes around all arguments in CONCAT_WS()
$query = "SELECT author_id, CONCAT_WS(' ', 'first_name', 'last_name')
AS name FROM author ORDER BY last_name, first_name ASC";
$result = mysqli_query ($dbc, $query);
// if the query fails and $result is = FALSE
// let's see what MySQL have to report about it
if(!$result){
echo '<br />'. $query .'<br />'. mysqli_error($dbc) .'<br />';
}
echo "\n<!-- # of rows found: " . mysqli_num_rows($result) . "-->\n";
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
echo "<option value=\"{$row['author_id']}\">{$row['name']}</option>\n";
}
mysqli_close($dbc); // Close the database connection.
?>
</select></p>
</form>
<?php
}// End of main conditional.
// Include the PHP footer.
include ('./includes/footer.php');
?>
When I view the html source of the page it shows these errors:
<b>Warning</b>: mysqli_query() expects parameter 1 to be mysqli, null given in <b>C:\xampplite\htdocs\website\test.php</b> on line <b>30</b><br />
<br />
<b>Warning</b>: mysqli_error() expects parameter 1 to be mysqli, null given in <b>C:\xampplite\htdocs\website\test.php</b> on line <b>35</b><br />
<br />SELECT author_id, CONCAT_WS(' ', 'first_name', 'last_name')
AS name FROM author ORDER BY last_name, first_name ASC<br /><br /><br />
<b>Warning</b>: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in <b>C:\xampplite\htdocs\website\test.php</b> on line <b>37</b><br />
<!-- # of rows found: -->
<br />
<b>Warning</b>: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in <b>C:\xampplite\htdocs\website\test.php</b> on line <b>39</b><br />
<br />
<b>Warning</b>: mysqli_close() expects parameter 1 to be mysqli, null given in <b>C:\xampplite\htdocs\website\test.php</b> on line <b>42</b><br />
Hope this is what you meant?