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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.