text data truncates when updating to MtSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jej1216
    New Member
    • Aug 2006
    • 40

    text data truncates when updating to MtSQL

    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
    Last edited by Atli; Sep 5 '08, 12:06 AM. Reason: Fixed the HTML tag
  • stepterr
    New Member
    • Nov 2007
    • 157

    #2
    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.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, JEJ.

      Try this:
      [code=php]
      $sev = htmlentities($s ev);
      <?php echo '<option value="', $sev, '">', $sev, '</option>'; ?>
      [/code]

      Alternatively, you could do this:
      [code=php]
      $sev = htmlentities($s ev);
      <?php echo "<option value=\"{$sev}\ ">{$sev}</option>"; ?>
      [/code]

      PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

      Comment

      Working...