I have an application that makes POST requests to a PHP file every second, via Ajax. If I try to split the string I receive in the $_POST array in php or I try to "json_decode" it, I get a 500 error. If I do not make any of these actions, I don't get any error. Why?
This is the PHP code that handles the Ajax request (using two POST variables):
<?php
$mysqli = new mysqli(*data*);
if (is_string($_POST["lid"]) && (is_string($_POST["price"]) || is_integer($_POST["price"])) && 0===1) {
$li_id = $_POST["lid"];
$esc_li_id = $mysqli->real_escape_string($li_id);
$li_price = intval($_POST["price"]);
if ( ($li = $mysqli->query("SELECT listing_id, price, buyer_id, auction_name FROM listings WHERE listing_id = '$esc_li_id' AND schedule_requested = '1' AND finished = '0'")) && ($mysqli->affected_rows > 0) ) {
if ( intval($li["price"]) !== $li_price ) {
$response = array($li["price"], $li["buyer_id"], $li["auction_name"]);
if ($logged === 1) {
$response[] = $user_id;
}
echo json_encode($response);
} else {
echo "err";
}
} else {
echo "err";
}
} else echo 'err'; ?>
If the code inside the outer "if" gets to be executed, it returns a 500 error. If I put a && 0 === 1
into the outer "if", no error is returned.
Your PHP code is trying to do something incorrectly, thus breaking the call and returning a 500 error. Check to see that the information you are receiving in the POST is what you are expecting, perhaps it is not a string and that is why your string manipulation operations aren't working