0

I did try searching for this but couldn't find any answers...

I'm working on a maintenance webpage for some in-house tasks at work. I'm using a combination of jQuery and PHP to send data to and from a mySQL DB. I have a form on my screen which, once the user enters some data, they can hit "Save" when sends the data to a PHP script via $.getJSON(). Everything works perfectly, and my data gets updated, UNLESS, one of my fields (notes) contains a large amount of data - then I get an Notice: Notice: Undefined index: notes, and while my code doesn't stop, it updates my notes field in my DB to be empty.

Here's a simplified example of what it's doing:

JavaScript:

var data = new Object();
data.id = $('#edit-id').val();
data.notes = $('#edit-notes').val();

$.getJSON('functions.php?action=updateData', {saveData: data}).done(function(JSONData){console.log(JSONData)}});

PHP:

if ($_GET['action'] == 'updateData')
{
    $data = $_GET['saveData'];
    $DBH = db_connect();
    if ($DBH)
    {
        $STH->prepare('UPDATE `Clients` SET `Notes` = :notes WHERE `ID` = :clientid');
        $STH->bindValue(':clientid', $data['id'], PDO::PARAM_INT);
        $STH->bindValue(':notes', $data['notes'], PDO::PARAM_STR);
        if (!$STH->execute())
            //error handling stuffs...
        else
            print json_encode(array('errors'=>0));
    }
}

So, if I run this code and have my notes field be something short and simple: this is a test, then everything works fine, and I have my notes in the DB. If I send something larger, though (couple hundred characters), then it doesn't work. If I do: print_r($data), it shows me that my array is only:

Array
(
    [id] => 1
)

But, my Headers show:

action: updateData
saveData[id] = 1
saveData[notes] = {my really long notes}

Is there something I'm missing?

SeiferTim
  • 438
  • 4
  • 18
  • 1
    Could it be the length of your GET is too large? http://stackoverflow.com/questions/7724270/max-size-of-url-parameters-in-get Have you checked that the server receives the message? Also, does the database error (could be the field size for the database column)? – Graham Walters Jan 15 '14 at 17:00
  • 1
    You should really be using POST for updates to data anyway – Mark Baker Jan 15 '14 at 17:03
  • Is suhosin running and eliminating the get-variable from the query string probably? – Axel Amthor Jan 15 '14 at 17:06
  • My suhosin.get.max_value_length is 512 according to PHP Info... I didn't realize there were differences in GET and POST other than how it's sent - I usually use GET for debugging and development and then switch to POST when I'm ready for it to go live... I'll switch to POST and see if that does it! Thanks guys! – SeiferTim Jan 15 '14 at 17:08
  • Looks like your example is missing a `'` too.. might want to correct that. – brandonscript Jan 15 '14 at 17:25

1 Answers1

0

What I did not realize: there are two separate limitations on the maximum length of GET and POST requests.

Either setting suhosin.get.max_value_length to something huge, OR changing my GET requests to POST instead (which is better for this case anyway) fixed this problem.

Thanks, Graham Walters, and Mark Baker!

SeiferTim
  • 438
  • 4
  • 18