Data is not pulling from mysql db into php app - textarea field issue - maybe?

I have an issue that I originally blamed on tinyMCE [and part of it was related to tinyMCE], but now after much research, I 'think' this new issues has something to do with Textarea field limits, db field limits, something...

I have a php web form, in addition to the other fields, there are three text area fields, that allow the user to enter comments that will display at the top of the form, end of form and on thank page.  TinyMCE is attached to these fields, so user can format their text. After resolving the funky chars that were appearing in my db because of Word copy/pasting, the issue I now face is that after the text has been submitted to the db, if it is very long amount of text, it will not pull/display on the php page.  

For example, I enter a 100 word paragraph, save it to the db, open the web page, I see the text.  Now if I add 1K words, 2K words of text, nothing appears on the web page, not even the div border that I have set to encase this text.  It's like nothing is in the db field, but if I go to the db, to that field, I see all the text.  Then if I remove 90%, 80%, etc of the text, update the db, open the web page, the text is then viewable.

I have changed field type from "text" to "mediumText", increased column in the textarea field to 40 from 16.  Nothing is working.  What else do I need to consider, do, try, etc?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
If all of the text is there in the database, then it has Nothing to do with the database.  Changing the field type does not affect the problem.  The problem will be somewhere in the code that puts up the text on the web page.

You should be able to write a short test page that displays the fields on a web page without any formatting to see that it really is in the database and can be retrieved.
Ray PaseurCommented:
Do you have phpMyAdmin?  If so, look in the data base and tell us if the data is getting there, please.

You may want to put some debugging traps into the existing code.  This one is particularly useful.
HainKurtSr. System AnalystCommented:
copy paste one of the data which is not showing into a text file and paste here...
also show the code that uses this piece on your php page...
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Ray PaseurCommented:
I see from the other question that the data is getting into the data base -- it's just not getting back out.  That leads me to believe that there may be embedded control information (perhaps an unclosed HTML tag).  

When you echo the information from the data base do you escape it through htmlentities() ?
justmelatAuthor Commented:
Yes Ray that is correct, just not getting back to my php page - but again, only when there is "too much" text.

I don't think so, but let me check on the htmlentities().

Thank you
Ray PaseurCommented:
One way you can check is to use View Source to see what is in the HTML document.
It may be the packet limit for the MySQL database. Basically, when the database transmits all the record data back to your script, it has a limit on the size. If the total size of that package exceeds a certain amount (called the max_allowed_packet), then you might not get your data back properly.

1. Does your query contain a SELECT * or do you specify the fields you want, like SELECT fieldA, fieldB, fieldC ?

2. What does your table structure look like besides that one field? So if you were to look at the CREATE TABLE query for your table, what would it say? I'm mostly interested in whether you have file attachments / blob data in the same table, but the CREATE TABLE will explain that.

3. Have you tried taking your query when it does NOT work and then run it on the MySQL command line? If not, give that a try and see if you get any errors that might help explain things.
justmelatAuthor Commented:
HI Ray

I did do View Source and it's like nothing was created for that area.  The div's do not show, just nothing.  But of course If I reduce the amount of text, everything appear on the form and in view source.
justmelatAuthor Commented:

1) it is Select *

2) Here is the table structure
CREATE TABLE `account` (
  `account_name` varchar(128) NOT NULL,
  `account_url` varchar(256) DEFAULT NULL,
  `logo_url` varchar(256) DEFAULT NULL,
  `request_start_value` int(11) DEFAULT NULL,
  `email_from` varchar(128) DEFAULT NULL,
  `email_to_on_submission` text,
  `email_to_on_approval` text,
  `number_of_request_per_page` int(11) DEFAULT NULL,
  `login_required` tinyint(4) DEFAULT NULL,
  `allow_edit_after_approval` tinyint(4) DEFAULT NULL,
  `account_client_name` varchar(128) NOT NULL,
  `header_background_color` varchar(128) DEFAULT NULL,
  `header_tab_color` varchar(128) DEFAULT NULL,
  `header_tab_over_color` varchar(128) DEFAULT NULL,
  `header_tab_text_color` varchar(128) DEFAULT NULL,
  `copy_request_link_color` varchar(128) DEFAULT NULL,
  `show_save_finish_later_btn` tinyint(4) DEFAULT NULL,
  `include_request_in_email` tinyint(4) DEFAULT NULL,
  `required_asterisk_color` varchar(128) DEFAULT NULL,
  `aux_account_id` int(11) DEFAULT NULL,
  `aux_base_url` varchar(256) DEFAULT NULL,
  `enable_copy_from_request` tinyint(4) DEFAULT NULL,
  `default_requester_id` int(11) DEFAULT NULL,
  `requestor_email_field_label` varchar(128) DEFAULT NULL,
  `onload_js_function` varchar(128) DEFAULT NULL,
  `onsubmit_js_function` varchar(128) DEFAULT NULL,
  `custom_js` text,
  `intro_text` mediumtext,
  `confirmation_message` mediumtext,
  `attachment_message` mediumtext,
  `created_by` int(11) DEFAULT NULL,
  `create_date` datetime DEFAULT NULL,
  `modified_by` int(11) DEFAULT NULL,
  `modified_date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)

Open in new window

3) I will give this a try.
justmelatAuthor Commented:

you mentioned  max_allowed_packet, where can I find this value to view it's settings.
justmelatAuthor Commented:
found max_allowed_packet, up'd it to 32m, thin 64 - no change
Dave BaldwinFixer of ProblemsCommented:
Here is a Very simple PHP page that you can use to check what your database is returning and how it shows on the page.  Put your own connection info in there and the fields you want to check in the query.  I put your text fields in there so you can run this and see what it looks like without the formatting.

// DB configuration
$dbhost = "server";    // Your database server
$dbuser = "username";      // Your db username
$dbpass = "password";      // Your db password
$dbname = "database";      // Your database name

//mysql_connect('localhost', 'mysql_user', 'mysql_password');
$dbh = mysql_connect($dbhost, $dbuser, $dbpass);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<title>dbCheck PHP MySQL</title>
echo "$dbhost <br>";
<h1>dbCheck PHP MySQL</h1>
$result = mysql_query("SELECT `email_to_on_submission`, `email_to_on_approval`, `intro_text`, `confirmation_message`, `custom_js`,`attachment_message` FROM `account` LIMIT 5");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo '<p>=======================<br>';
echo $row[0].'<br>';
echo $row[1].'<br>';
echo $row[2].'<br>';
echo $row[3].'<br>';
echo $row[4].'<br>';
echo $row[5].'<br>';
echo '</p>';


Open in new window

Ray PaseurCommented:
Here is the general design of a very simple query-and-test that might help you see what MySQL is doing with your data.

$sql = "SELECT * FROM accounts WHERE (whatever)";
$res = mysql_query($sql);
if (!$res)
    echo "FAIL $sql <br/>";
$row = mysql_fetch_assoc($res);

The point of testing the value of $res with that if() statement is that MySQL is not a black box (as we have seen here) and it can and will fail for reasons that are outside of your control.  So it is important to test and do data visualization when something like this is occurring.
justmelatAuthor Commented:
DaveBaldwin  thanks for that, it helped confirm that I am not losing my mind.  

I set up this page and ran/opened it.  The query results show all of the text, but when I switch and look at the real php page only part of the text is there

There also a textarea field that will display text in the bottom portion of the page [attachment_message], that text is not displaying at all, though in the query results of your page, I see everything.

If I remove the text from the intro_text db field, then the text will show up where it's suppose to on the form.

I just don't get this.
justmelatAuthor Commented:
here is a clearer example of what is happening:

refer to example text attached [this is just latin demo text so ignore the odd/special char.  in the real text, I have removed everything that even appears to be a special char]

If i put the entirety of this text into the db, then it will not appear in my php form.

if I remove the last paragraph or the last two paraghaphs from the text in the db, it will appear.

The other problem that I just noticed is that even when the  # of paragraghs have been reduced to three instead of five, the two other textarea fields that should display, do not

but, if for example, I remove all text except for the text in the first paragraph, then everything shows/displays as it should.

I think this tells me there is a limit to something, somewhere, that I have to address, but I don't know what or where that something is.
Ray PaseurCommented:
What is the URL that exhibits this problem in action?
justmelatAuthor Commented:
Hi Ray_Paseur - I'm getting the same result as with Dave basically.  I see that all the text is actually in the db.  The query does not fail.
justmelatAuthor Commented:
Hi Ray_Paseur - I wish I could, but I don't want to be out of a job.

Let me ask this questions - is there such a thing as a php buffer limit?
justmelatAuthor Commented:
Ok, I hope I am getting close.  I ran my debugger for the 100th time and saw this [refer toimage], the var that is holding the intro text [session->userdata->ACCOUNT_INTRO_TEXT] saids 1024 (2963) for length.  

I assume this means - nevermind, what does this mean?
justmelatAuthor Commented:
So the session var length/size is 1024, but 2963 are being send, so var is truncating.  How to out increase the size of this session var?
what is the memory_limit in your php.ini? Do you have to store this db field in a session variable?
HainKurtSr. System AnalystCommented:
looks like this is not db issue, db is stored correctly, it is retreived correctly from db, but somehow in your code you are doing something and losing the data if it is above some limit...

and I guess you never posted the php code that shows how to run query, get data and display on your page...
justmelatAuthor Commented:
FINALLY! FINALLY -because of the questions and suggestions from you guys, I finally discovered what was wrong -  there is a size limitation for the amount of data stored in the session object.  And as per RFC 2109 this size limit is 4KB.  THat was it.  I knew I was hitting some limit somewhere, finally figured it out where it was. Had to re-write some code so I could pull only these text section and not rely on the data stored in the session.

Thanks so much guys.

Ray, David, Gr8 - you guys mind splitting the points?
Dave BaldwinFixer of ProblemsCommented:
Fine with me.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
justmelatAuthor Commented:
Helped me get to the actual problem and then solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.