By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

text data truncates when updating to MtSQL

P: 40
I have a series of scripts that allow the user to a) create new data to insert into a MySQL DB, b) review that data, and c) change that data and do an update to the MySQL DB.

For a), I use a basic html form, and it passes a sample value like this:
[[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]

This inserts the full text into the DB, and it shows this full text for b).

For c), I use a php page, and it displays the value correctly using this:
[PHP]$sev=$myrow["severity"];[/PHP]
and
[PHP]<?php echo "<option value = ".$sev.">".$sev."</option>"; ?>[/PHP] followed by the choices if needing to be changed:[HTML]<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]
If I re-select the same choice in the php page, the data is again submitted to the DB and the update is the full text value. If, however, I leave that data alone and submit, it gets truncated to 'Level2.'

The PHP page is not passing the [PHP]<?php echo "<option value = ".$sev.">".$sev."</option>"; ?>[/PHP] value.

This issue occurs only for the drop down fields. I have other text fields that are not drop-downs and they do not truncate.

I have searched other posts and it seems I need to enclose $sev with quotes, but I get errors when I try that.

TIA,

jej1216
Sep 4 '08 #1
Share this Question
Share on Google+
2 Replies


stepterr
100+
P: 157
How have you tried using quotes around $sev? Were you doing double quotes? If so try using single quotes inside of the the double quotes.
Sep 16 '08 #2

pbmods
Expert 5K+
P: 5,821
Heya, JEJ.

Try this:
Expand|Select|Wrap|Line Numbers
  1. $sev = htmlentities($sev);
  2. <?php echo '<option value="', $sev, '">', $sev, '</option>'; ?>
  3.  
Alternatively, you could do this:
Expand|Select|Wrap|Line Numbers
  1. $sev = htmlentities($sev);
  2. <?php echo "<option value=\"{$sev}\">{$sev}</option>"; ?>
  3.  
http://php.net/string
Sep 17 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.