Maximum characters in a POST form?

I’ve got a database of magazine articles and I was wanting to write an interface for it so that I could enter and edit articles online instead of having to go into phpMyAdmin. When I tried to edit an existing article through my interface, I got the following message:

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

I tried several different things to try to figure out the problem. Finally, I deleted the entire text of the article (saving it first, of course) and everything worked. The article is about 3.6 K characters long, so I’m beginning to suspect that the server won’t accept anything over a certain size. Does anyone know if that’s true? How about if I split the article up into bits that are less than 1K each? Would it take it then or is the problem that it won’t take the total amount, no matter how it’s split up?

As I’m sure you have figured out, there are several things that might be at play here . I assume you are using MySQL (since you mentioned phpMyAdmin), and that you have the target field set up as a type that is appropriate for the amount of data you need to store :wink: .

You didn’t indicate what language you’re using to write your script, and that can have a bearing on how you have to code the interface.

Other than limitations imposed by your language (for instance, certain settings in the PHP configuration), your data-type, or your code, I do not believe there is any “theoretical” maximum number of characters you submit via POST. Practically speaking, there does come a point when processing too large of a POST can create problems in a shared hosting environment because of execution time limits, etc.

Your error message looks a lot like the script either timed out, or MySQL couldn’t handle the query - but of course, that is just a guess at this point.

Maybe if you post back with a little more info (are you using perl, python, PHP - version #, etc. ?), and possibly a code snippet or two, we can provide more help. :slight_smile:


I’m using php 5.12 to create a form. And, yes, it is to go into MySQL, into a field that will hold the data, indeed already does hold the data.

I have several other forms that are written similarly, although none of them have a textarea to hold the same amount of data. I only get the error message when I submit the form with a large amount of data. I don’t think MySQL is a factor because I temporarily removed the code which actually wrote the data to the database and I still got the error. It’s also not a timing out issue, or shouldn’t be, because the error message comes up immediately after clicking the submit button.

I don’t think it’ll do a whole lot of good, but here’s the code that I use to create the form

if ($cmd == ‘edit’)
$textarea_end = ‘</’ . ‘textarea’ . ‘>’;

if (isset($_GET[‘EditID’]))
$ID = $_GET[‘EditID’];
$query = db_query(
“SELECT * FROM articles
$row = mysql_fetch_assoc($query);

$Title = stripslashes($row[‘Title’]);
$Author = stripslashes($row[‘Author’]);
$Date = $row[‘Date’];
$Publication = stripslashes($row[‘Publication’]);
$Web = stripslashes($row[‘Web’]);
$Link = stripslashes($row[‘Link’]);
$Text = stripslashes($row[‘Text’]);
$Hide = $row[‘Hide’];
$Category_ID = $row[‘Category_ID’];
$date_added = $row[‘date_added’];
$action = “update”;
$ID = ‘’;
$Title = ‘’;
$Author = ‘’;
$Date = ‘’;
$Publication = ‘’;
$Web = ‘’;
$Link = ‘’;
$Text = ‘’;
$Hide = ‘’;
$Category_ID = ‘’;
$date_added = date(‘Y-m-d’);
$action = “add”;

echo ’

Help Date
Help Web
Help Link
Help Text ' , $Text , $textarea_end , '
Help Hide
Category '; $query_cat = db_query( "SELECT * FROM article_cats ORDER BY sort", __FILE__, __LINE__); while ($row_cat = mysql_fetch_assoc($query_cat)) { if ($row_cat['cat_ID'] == $Category_ID) echo ' ' , $row_cat['Category'] , ''; else echo ' ' , $row_cat['Category'] , ''; } echo '
'; }

I don’t have enough dba experience to clearly articulate this, but I am going to try in the hopes that this might lead more knowledgeable people in a useful direction. First, you mentioned that the problem happens when you perform an update. This page only shows SELECT queries, which are evidently not a problem for you.

Personally, I think the problem is due to some sort of deadlock issue rather than the size of your inserts. I’m migrating a zipcode radius search I did in CF/MSSQL to PHP/MySQL which required me to extract 30,000 records containing 4 double-precision floats in PHP using an ODBC driver, and used the record set to generate several SQL insert scripts that are about 600k each. I posted these scripts using a webform to a PHP page that parsed the files and performed the inserts. Approximately 5000 insert queries per request, all executed using a single db request. It worked fine.

I have a couple thoughts on what might be the problem, but it’s hard to say without seeing the action page.

Depending on how you designed your database you might keep article details in one table, and then have a generic “Big Text Stuff” table that can be utilized by several different tables, using a foreign key constraint. That probably isn’t the case though, since your first query pulls everything from just one table (articles).

My second guess is that your action page executes an update and also runs some sort of select query in order to do some type of housekeeping. What type of tables are you using? I think the default for MySQL 5 is MyISAM, which uses table level locking. InnoDB uses row locking, so is prone to less problems in some instances.

Update queries on MyISAM exclusively lock the whole table down until they’re done with their transaction. It supports concurrent selects/updates but that’s a problem if you’re trying to select a record from the row you’re updating. Maybe the added overhead of the longtext field just tips the scales so that the lock isn’t given up in time?

If the Select is grabbing from an unrelated row in that table, it should not deadlock. If you’re performing a select in order to complete your update statement though, it can’t happen because the update takes priority over the select. MySQL knows this and instead of waiting for the server to time out, it just goes ahead and pukes right away.

Want to share the other part of your script? Might be able to offer some insight. Like I said though, I am not a dba. I’m just using a little deduction in the hopes that we can help.

The action part of the script at this point is

if ($cmd == “submit”)
// isset($_POST[‘ID’]) ? $ID = $_POST[‘ID’] : $ID = ‘’;
// isset($_POST[‘Title’]) ? $Title = $_POST[‘Title’] : $Title = ‘’;
// isset($_POST[‘Author’]) ? $Author = $_POST[‘Author’] : $Author = ‘’;
// isset($_POST[‘Date’]) ? $Date = $_POST[‘Date’] : $Date = ‘’;
// isset($_POST[‘Publication’]) ? $Publication = $_POST[‘Publication’] : $Publication = ‘’;
// isset($_POST[‘Web’]) ? $Web = $_POST[‘Web’] : $Web = ‘’;
// isset($_POST[‘Link’]) ? $Link = $_POST[‘Link’] : $Link = ‘’;
// isset($_POST[‘Text’]) ? $Text = $_POST[‘Text’] : $Text = ‘’;
// isset($_POST[‘Hide’]) ? $Hide = $_POST[‘Hide’] : $Hide = ‘’;
// isset($_POST[‘Category_ID’]) ? $Category_ID = $_POST[‘Category_ID’] : $Category_ID = ‘’;
// isset($_POST[‘date_added’]) ? $date_added = $_POST[‘date_added’] : $date_added = ‘’;
// isset($_POST[‘cmd2’]) ? $cmd2 = $_POST[‘cmd2’] : $cmd2 = “add”;
$set = ‘’;

// $Title <> ‘’ ? $set .= ‘Title = ’ . "’" . addslashes($Title) . “’, " : $set .= 'Title = NULL, ';
// $Author <> ‘’ ? $set .= ‘Author = ’ . "’” . addslashes($Author) . “’, " : $set .= 'Author = NULL, ';
// $Date <> ‘’ ? $set .= ‘Date = ’ . "’” . $Date . “’, " : $set .= 'Date = NULL, ';
// $Publication <> ‘’ ? $set .= ‘Publication = ’ . "’” . addslashes($Publication) . “’, " : $set .= 'Publication = NULL, ';
// $Web <> ‘’ ? $set .= ‘Web = ’ . "’” . addslashes($Web) . “’, " : $set .= 'Web = NULL, ';
// $Link <> ‘’ ? $set .= ‘Link = ’ . "’” . addslashes($Link) . “’, " : $set .= 'Link = NULL, ';
// $Text <> ‘’ ? $set .= ‘Text = ’ . "’” . addslashes($Text) . “’, " : $set .= 'Text = NULL, ';
// $Category_ID <> ‘’ ? $set .= ‘Category_ID = ’ . "’” . $Category_ID . “’, " : $set .= 'Category_ID = NULL, ';
// $Hide <> ‘’ ? $set .= ‘Hide = ’ . "’” . addslashes($Hide) . “’, " : $set .= 'Hide = NULL, ';
// $date_added <> ‘’ ? $set .= ‘date_added = ’ . "’” . $date_added . "’ " : $set .= 'date_added = NULL ';
echo $set;
//if ($cmd2 == ‘add’)
// {
// db_query(
// INTO articles
// SET $set”, FILE, LINE);
// echo "article added
// }
// else
// {
// db_query(
// “UPDATE articles
// SET $set
// WHERE ID = ‘$ID’
// echo "article updated
// }

Notice that everything is commented out, except for

$set = ‘’;


echo $set;

I get the error whether or not I send the data to the database, so I don’t see how it can be a database problem. I don’t get the error when I send the data to the database in my other scripts, all of which are identical in structure to this one, except that there’s no large chunks of data.

I’m not trying to be argumentative. Really. :slight_smile:

[quote]I have several other forms that are written similarly, although none of them have a textarea to hold the same amount of data.

I’m not trying to be argumentative. Really. :)[/quote]
No worries, Mate. I guess that I might have come off like kind of a jerk, but I’m not typically. :wink:

I’m a little confused now, especially since there is nothing db related on your action page. Does that page load if you go to it directly? I guess it might blow up on the reference to a nonexistant “$cmd”, but at least it’s something other than a 500 error.

This display page is the same one you come to for both add and edit right? Something about this code looks odd to me…

if ($cmd == 'edit') { $textarea_end = '</' . 'textarea' . '>'; Does everything look good when you check the rendered source code of the html before you click submit? Maybe try updating a record with like 500 "a"s instead of real content and see if it succeeds. You’ve got a weird one on your hands here.

There are a couple things at play here that I can think of:
post_max_size. This is the cumulative data of all fields submitted, as well as control information I think. You can see what this is set to by creating a page with just phpinfo(); on it. Mine is set to 8M, but I won’t assume all DH installations are the same. You should be able to change this with an ini_set. (I can’t find anything for apache stating a limit for post data.)

Other thing, if you’re doing some processing (especially over that large of text), you may be bumping against a script timeout. Default is typically 30 seconds. You could try doing set_time_limit(x) where x is some seconds value. It could be php processing taking too long, or even the combination of processing and just apache sending the data to php then php taking too long to actually construct the post array.

To narrow it down, though, I’d create a page that just has your form which submits to itself and just displays the submitted data. If that works, start adding more code back to see where the problem introduces itself.


I can’t go to it directly. It’s all one program, with the different sections being governed by switches.

[quote]if ($cmd == ‘edit’){
$textarea_end = ‘</’ . ‘textarea’ . ‘>’;
I knew that would have people scratching their heads. :slight_smile: I’m working through a portal and it gets all confused if I use a closing textarea tag directly, so I have to use a variable.

Thanks for working with me on this. I have one other possible place to try before I give up on this part of the script and just resign myself to adding and editing through phpMyAdmin.

I checked post_max_size. It’s 8M for me, too, so that’s not the issue.

I know it’s not a timeout because the error happens within a second of submitting the form

I did what you suggested. Same problem.

I am using a portal and maybe the problem is that I’m going through an “eval” command to run everything. I’ve got one other place to try to work on this and then another possibility that is a bit odd, but just might be a way to work around it. You know what they say about there being more than one way to skin… (oops! my cat just glared at me! :slight_smile:

Thanks for your help. You’ve helped to narrow things down a bit at least.

Actually, that’s what did the trick. It worked having a whole bunch of "a"s. So then I tried the actual text again. Didn’t work. So I looked closely at it and realized that maybe the linebreaks – < br /> – were a problem. Sure enough. I replaced all of them with linefeeds and everything worked perfectly. I just had to add a line to str_replace the linefeeds with html linebreaks and it all works.

Thanks so much to all of you for your assistance. It means a lot to know I can come here and at least have a place to vent when I’m getting frustrated.