Jump to content

mySQL query not pulling into HTML properly


bassdog65

Recommended Posts

here is my code snippet:

 

<div><b>Category Name:</b> 
<p><input type="radio" name="category" value="existing" <?php if (isset($_POST['category']) && ($_POST['category'] == 'existing') ) echo ' checked="checked"'; ?>/> Existing =>
<select name="existing"><option>Select One</option>
<?php 
$x = "SELECT category FROM artists";		
$y = mysqli_query ($dbc, $x);
if (mysqli_num_rows($y) > 0) {
	while ($row = mysqli_fetch_array ($y, MYSQLI_NUM)) {
		echo "<option value=\"$row[0]\"";

		if (isset($_POST['existing']) && ($_POST['existing'] == $row[0]) ) echo ' selected="selected"';
		echo ">$row[1]</option>\n";
	}
} else {
	echo '<option>Please add a new category.</option>';
}
mysqli_close($dbc); 
?>
</select></p>

<p><input type="radio" name="category" value="new" <?php if (isset($_POST['category']) && ($_POST['category'] == 'new') ) echo ' checked="checked"'; ?>/> New =>
<input type="text" name="category_name" size="20" maxlength="40" value="<?php if (isset($_POST['category_name'])) echo $_POST['category_name']; ?>" /></p>
</div>

 

Im trying to give the user the option of picking a category already in the database, or to make a new one.  For some reason the result is not displaying in my dropdown when there are already categories in the database.  When I run the mySQL query in phpMyAdmin it returns results.  What am I missing?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.