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?