I would be great if someone could spot the problem with this code please.
I have a MySQL table that was populates an Options list which works well when adding new records to another database table.
The code is:
$query="SELECT id, types FROM $table ORDER BY types ASC";
$result = mysql_query ($query);
echo "<select name=\"type\">";
echo "<option value='Select from list.....'>Select from list.....</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[types]>$nt[types]</option>";
}
echo "</select>";
In an EDIT program I required the Options list item previously selected when adding the record to be 'echo'd back'.
I changed the above code to do this as shown here - See Line 4 changes: ($type is the data field read from the SQL table)
$query="SELECT id, types FROM $table ORDER BY types ASC";
$result = mysql_query ($query);
echo "<select name=\"type\">";
echo "<option value=$type>$type</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[types]>$nt[types]</option>";
}
echo "</select>";
?>
When using this code the Options list selected when creating the record is echo'd back correctly using the above code in the Edit program.
BUT if the Options list item cotains a space between 2 words then only the first word is saved and the second word is lost.
So for example BOOK SHOP is saved as BOOK. If I go and edit the data item in the options table from BOOK SHOP to BOOK-SHOP then it is not lost!!
Thanks in advance for any suggestion
Stephen