Reputation: 3
I have a php code which generates a list from a field in mysql table. When I submit the information into another database it doesnt show anything after the space - just the first word (for example, if i choose 'robe spot' from the drop down and sumbit only 'robe' is inserted into the database)
Here is my php code:
<?
$dbHost = 'localhost'; // localhost will be used in most cases
// set these to your mysql database username and password.
$dbUser = 'user';
$dbPass = 'pass';
$dbDatabase = 'stock'; // the database you put the table into.
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("stock") or die(mysql_error());
$query="SELECT category FROM subcategory_table";
/* You can add order by clause to the sql statement if the names are to be displayed
in alphabetical order */
$result = mysql_query ($query);
echo "<select name='category'>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[category]>$nt[category]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
I'm looking for the correct code so it allows spaces when submitting back into the database
Thank You
Upvotes: 0
Views: 1355
Reputation: 310
Modify your code as:
echo '<option value="' . $nt[category] . '">' . $nt[category] . '</option>';
The problem is the option value. It should work.
Upvotes: 6