Results 1 to 4 of 4
Related
-
Form Data to XML Forum: Javascript Forum
Replies: 0 -
Hi! How to get data from popup window into a text box Forum: Javascript Forum
Replies: 0 -
Hi! How to get data from popup window into a text box Forum: Introduce Yourself
Replies: 0 -
php data order Forum: PHP Forum
Replies: 1
-
09-09-2008, 04:17 PM #1
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> </select>
The edit php code does this:
php displays the data from:
PHP Code:$sev=$myrow["severity"];
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>
</select>
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?!?)
TIA,
jej1216Last edited by jej1216; 09-09-2008 at 04:24 PM. Reason: Omitted information before
-
09-09-2008, 09:44 PM #2
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:
Code:<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>
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
-
09-10-2008, 09:40 AM #3
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.
-
12-27-2008, 11:29 PM #4
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.
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum