Martin Oxby
Martin Oxby

Reputation: 23

TextArea not saving to mySQL if over 512 Bytes

I've been searching for ages and can't find this precise problem, but feel free to point me in the right direction if it has.

Simple Description: have a page that has a TEXTAREA on it. This TEXTAREA is to accept HTML as it's used to edit the home page of a client's website.

The aim is for this TEXTAREA to save to a VERY simple mySQL table.

PROBLEM: The problem is that if the TEXTAREA exceeds 512 characters is saves nothing to the database field. Under that it stores it fine.

Here's the code:

$homeTopLeft = addslashes(htmlentities($_GET['homeTopLeft'], ENT_QUOTES | ENT_IGNORE, "UTF-8"));
$homeNews    = addslashes(htmlentities($_GET['homeNews'], ENT_QUOTES | ENT_IGNORE, "UTF-8"));

mysql_login();

$query = "UPDATE cmsData SET homeTopLeft='$homeTopLeft', homeNews='$homeNews', lastUpdated=NOW() WHERE entry=1";
$result = mysql_query($query) or die(reportError('Unable to save new CMS data'));
if (mysql_affected_rows() > 0) {
    echo '<p class="ok">Pages Successfully Updated!</p>';
    echo '<p style="border:1px dashed #ccc;">homeTopLeft = ' . $homeTopLeft . '</p>';
} else {
    echo '<p class="err">Unable to update the home page</p>';
}

I currently have the $_GET method as I'm actually calling the function via AJAX, which works fine under 512 characters.

What It's Not - It's not the mySQL field size: Its data type is TEXT and I've manually increased the field through phpMyAdmin without error. - It's not (as far as I can tell) the AJAX call, because it works if the TEXTAREA is < 512 Bytes - The Collation (I don't think: I have it set to latin1_general_ci and have tried latin1_bin and some of the UFT ones)

Final Note The actual database size of the field homeTopLeft has to be greater than 512 Bytes because of the htmlentities call.

I should also add that this occurs whether I'm just using a plain TEXTAREA or a tinyMCE rich text editor.

Any help you could offer would be gratefully received. Thanks!

Upvotes: 0

Views: 1465

Answers (3)

Ron
Ron

Reputation: 1336

Use mysql_real_escape_string over addslashes(htmlentities()). htmlentities normally should not go into the database. In addition to that, your database should use UTF8 for the table-charset, so sorting etc will be correct on foreign-language characters if you use them.

There is no known problem with text, that is larger than 512 bytes(!), if the corresponding field accepts it.

Upvotes: 0

haynar
haynar

Reputation: 6030

if you use GET method in your ajax you can't pass so much data to server as you wish, change it to POST and everything will work just fine.

Here you can find a short overview about that: http://www.boutell.com/newfaq/misc/urllength.html

Upvotes: 1

MrGlass
MrGlass

Reputation: 9262

There is a size limit on GET requests. For large things such as this, use POST

Upvotes: 5

Related Questions