I have a jQuery $.post function sending data to a PHP file which updates a DB field, grabs 1 of the values being sent to the file, adds '1' and returns the new value.
My PHP file looks as follows:
$varID = $_GET['varID'];
$varKey = $_GET['varKey'];
$varCurrentValue = ($_GET['varCurrentValue'] + 1);
update_comment_meta($varID, $varKey, $varCurrentValue);
echo $varCurrentValue;
My firebug response, if I'm understanding it correctly, confirms that the value's are being sent correctly to the PHP file: http://cl.ly/2P1Y0E3710442V3I143K [img]
However the only response that I'm getting is the "1" that I'm adding in the 3rd line of code, not the value of the sum that I should be getting.
I'm sure it's something really simple, but I'm just not seeing it...
Thanks for your help!
I looks like you are reading GET from php and sending POST.
Change to
$varID = $_POST['varID'];
$varKey = $_POST['varKey'];
$varCurrentValue = ($_POST['varCurrentValue'] + 1);
update_comment_meta($varID, $varKey, $varCurrentValue);
echo $varCurrentValue;
You can always just use $_REQUEST[] which will give you both GET and POST as well.
If I've understood correctly, you are sending data using HTTP POST
and getting them in PHP using $_GET
which refers to HTTP GET
, you should get data using $_POST
in PHP or send data using HTTP GET
in jQuery.
Hope it helps.
If you're posting data, use the $_POST[]
php variable to retrieve the values. $_GET[]
is only for the parameters passed via the URL.
Further to the other answers about using $_GET
when you should have been using $_POST
-
If you use the $_REQUEST
superglobal it merges $_POST
, $_GET
and $_COOKIE
so you can switch which method you use in JavaScript without having to change the PHP code.