Background:
I have an PHP form that inserts data into a MySQL DB, and it works. [HTML] Severity of Incident:
<select name="severity" size="1">
<option value="">Select a Severity Option</option>
<option value="Level1 - No Obvious Harm">Level 1 - No Obvious Harm</option>
<option value="Level2 - Non-permanent Harm">Level 2 - Non-permanent Harm</option>
<option value="Level3 - Semi-permanent Harm">Level 3 - Semi-permanent Harm</option>
<option value="Level4 - Major Permanent Harm">Level 4 - Major Permanent Harm</option>
<option value="Level5 - Death">Level 5 - Death</option>
</select>[/HTML]
I have a PHP page that selects the data and displays it, and it works. [PHP]
$db = mysql_connect("myhost", "mylogon", "mypw"); mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM mytbl WHERE incident_id = '$_GET[id]'",$db);
$ID = $_GET['id'];
while ($myrow = mysql_fetch_array($result))
{
$sev=$myrow["severity"];[/PHP]
I have a PHP page that allows the user to open the data and update the fields, and I hope there is some Javascript that can help me with this piece.
[PHP]echo "<option value = ".$sev.">".$sev."</option>"; ?>
<option value="Level1 - No Obvious Harm">Level 1 - No Obvious Harm</option>
<option value="Level2 - Non-permanent Harm">Level 2 - Non-permanent Harm</option>
<option value="Level3 - Semi-permanent Harm">Level 3 - Semi-permanent Harm</option>
<option value="Level4 - Major Permanent Harm">Level 4 - Major Permanent Harm</option>
<option value="Level5 - Death">Level 5 - Death</option>
</select>[/PHP]
The issue I have is twofold, both involving drop-down text fields:
1) The selected data gets displayed in addition to the allowable choices, resulting in two items in the list that are identical
These are the allowed choices:
Level1 - No Obvious Harm
Level2 - Non-permanent Harm
Level3 - Semi-permanent Harm
Level4 - Major Permanent Harm
Level5 - Death
If $sev is 'Level2 - Non-permanent Harm' then when I open the page to update the data, the list shows:
Level2 - Non-permanent Harm
Level1 - No Obvious Harm
Level2 - Non-permanent Harm
Level3 - Semi-permanent Harm
Level4 - Major Permanent Harm
Level5 - Death
2) When I open this page and make a change anywhere and submit, all drop-down text fields that are from the original select are truncated at the first space encountered.
If I keep the $sev value as opposed to selecting a new value, the data that gets passed to the DB is:
Level2 (truncated after that space).
I've been banging my head around within PHP, and I am hoping there are some Javascript tricks I might use.
I need the user to see what exists currently in the data and I need them to see the available choices to use when changing the data, and I need the data to go into the DB on the update without truncating.
This page needs to have data that is user friendly, so I need the phrase 'Level2 - non-permament Harm' rather than 'Level2.' There are about 15 drop-down fields in this form that get truncated on the update.
This is a very newbie question - I have used js only for simple form validation at this point.
TIA,
jej1216