tags:

views:

66

answers:

1

i have a form that submits data to a database, i have a function that looks like this:

//connect 
foreach ($_POST as $key => $value) {
    $_POST[$key] = mysql_real_escape_string($value);
}

now when i post, SOMETIMES i get an error that says this:

Allowed memory size of 268435456 bytes exhausted

i figured out that when i do a linebreak, or press enter in the message field, then that is when it causes the error, otherwise it works normal. any ideas?

+1  A: 

Please try to reproduce the error with

$mysql = mysql_connect(...

printf("<pre>Debug: count(_POST)==%d</pre>", count($_POST));
foreach ($_POST as $key => &$value) {
  printf("<pre>Debug: strlen(_POST[%s])==%d</pre>", htmlspecialchars($key), strlen($value)); flush();
  $value = mysql_real_escape_string($value, $mysql);
}
printf("<pre>Debug: Done.</pre>");

Does this print something "unusual" before the "Allowed memory size of 268435456 bytes exhausted" message?

edit and btw: I don't "like" the way you're trying to handle the real_escape_string thingy for two reasons:

  • Leave _POST alone if possible, don't change its values. ( I'd make an exception for undoing magic_quotes though ;-) )
  • Only process those fields you know you will need. Don't write an "encode and store in the database everything that is in _POST" function though it might sound like a good idea and super-reusable code. If you want to keep it somewhat reusable pass an array with descriptions to the function. In that array you can e.g. store information like [name of form field, allowed data type/validation rules, database field name]
VolkerK