Solved

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

Posted on 2012-03-20
25
498 Views
Last Modified: 2012-03-28
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?
0
Comment
Question by:justmelat
  • 13
  • 5
  • 3
  • +3
25 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 37743781
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37744096
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.
http://us.php.net/manual/en/function.error-log.php
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 37744162
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...
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 37744202
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() ?
0
 
LVL 1

Author Comment

by:justmelat
ID: 37744292
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
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37744320
One way you can check is to use View Source to see what is in the HTML document.
0
 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 125 total points
ID: 37744680
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.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37744901
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.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37744969
gr8gonzo

1) it is Select *

2) Here is the table structure
CREATE TABLE `account` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `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`)
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=latin1;

Open in new window


3) I will give this a try.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37745033
gr8gonzq

you mentioned  max_allowed_packet, where can I find this value to view it's settings.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37745681
found max_allowed_packet, up'd it to 32m, thin 64 - no change
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 37745864
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.

<?php 
// 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);
mysql_select_db($dbname);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>dbCheck PHP MySQL</title>
</head>
<body>
<?php 
echo "$dbhost <br>";
?>
<h1>dbCheck PHP MySQL</h1>
<?php 
$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();
   exit;
}

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>';
}
?>

</body>
</html>

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37747224
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/>";
    die(mysql_error());
}
$row = mysql_fetch_assoc($res);
var_dump($row);

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.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37747270
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.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37747388
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.
exampleTextAreaText.txt
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37747448
What is the URL that exhibits this problem in action?
0
 
LVL 1

Author Comment

by:justmelat
ID: 37747453
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.
0
 
LVL 1

Author Comment

by:justmelat
ID: 37748197
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?
0
 
LVL 1

Author Comment

by:justmelat
ID: 37748553
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?
introTextVarLength.png
0
 
LVL 1

Author Comment

by:justmelat
ID: 37748696
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?
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 37750053
what is the memory_limit in your php.ini? Do you have to store this db field in a session variable?
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 37753716
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...
0
 
LVL 1

Author Comment

by:justmelat
ID: 37763746
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?
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 37763800
Fine with me.
0
 
LVL 1

Author Closing Comment

by:justmelat
ID: 37777123
Helped me get to the actual problem and then solution.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now