505 users online (0 members and 505 guests)  

  Results 1 to 4 of 4


  1. Form Data to XML    Forum: Javascript Forum
    Replies: 0
  2. Replies: 0
  3. Replies: 0
  4. php data order    Forum: PHP Forum
    Replies: 1
  1. #1
    jej1216's Avatar
    New User

    Join Date
    Sep 2008
    Albuquerque, NM

    Update of data using PHP truncates text data

    I have a series of HTML and PHP pages for an Incident Reporting system. The page I use to enter initial data works, and data is inserted into a MySQL DB. The data is mostly text, many with spaces.

    The PHP page that I use to select the data from a previously entered Incident report also works, displaying the data including text with spaces.

    Here is the issue: The PHP page that I wrote to update the DB truncates all text data that has a space that is a dropdown field. Text that is in a text field is not affected.

    Here is some of my code:

    The html page that creates the report has this code (for an example) and it creates the data correctly.

    HTML Code:
    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>
    The edit php code does this:
    php displays the data from:

    PHP Code:
    and passes this:

    HTML Code:
    <select name="severity" size="1">
    PHP Code:
    <?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>
    and it truncates at first space in the DB "Level2".

    BUT if you re-select it, then it goes into the DB without truncating. "Level2 - Non-permananet Harm"

    It truncates the $sev data, if that makes sense.

    I think the crux of the issue is that I am saying to update all fields, and when no change is made, the drop-down text data gets truncated.

    I have tried wrapping $sev with single or double quotes but that just causes a PHP error. Is it a case where I have to somehow have it compare field by field and only update the changed fields?

    Another issue - My PHP Page for updating the DB now shows not only the choices for the drop-down text that are legitimate, but it additionally shows the selected value from the DB.

    Level2 - Non-permanent Harm <-------------- from the select page of previously entered data
    Level1 - No Obvious Harm
    Level2 - Non-permanent Harm
    Level3 - Semi-permanent Harm
    Level4 - Major Permanent Harm
    Level5 - Death

    The only solutions I can think of are:
    * Don't use Drop-down text fields (not a good choice - there are about 15 drop-downs on the form)
    * Replace all spaces in the drop-downs with underscores (ugly)
    * Don't use text values in drop-downs that contain spaces at all but pass number values instead (not user friendly)
    * Update only the fields that get changed (how?!?)


    Last edited by jej1216; 09-09-2008 at 04:24 PM. Reason: Omitted information before

  2. #2
    vinyl-junkie's Avatar

    Join Date
    Sep 2005

    Re: Update of data using PHP truncates text data

    I don't know exactly what you're trying to do, but I think you should use a code value for your dropdown, like so:

    <option value="">Select a Severity Option</option>
    <option value="1">Level 1 - No Obvious Harm</option>
    <option value="2">Level 2 - Non-permanent Harm</option>
    <option value="3">Level 3 - Semi-permanent Harm</option>
    <option value="4">Level 4 - Major Permanent Harm</option>
    <option value="5">Level 5 - Death</option>
    So you actually store a 1, 2, 3, 4 or 5 in your database. Then use a code description table that translates the values 1 thru 5 to their corresponding descriptions.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    jthayne's Avatar

    Join Date
    Aug 2008

    Re: Update of data using PHP truncates text data

    Sounds to me like it is an issue in the database. The code looks fine to me. There are two things I would check. First, verify the field type in the database and make sure it is set to allow more than 6 characters. Second, double-check the insert/update query and make sure your quotes are in the right place. Make sure that any strings in the formatted query are surrounded by single quotes.

  4. #4
    Maldrex's Avatar
    New User

    Join Date
    Dec 2008

    Re: Update of data using PHP truncates text data

    Check what you get in post (print_r($_POST), check what you have in DB. Maybe you have too small cell size in bd.

    Or use digital ID - it true.

Tags for this Thread