Have almost certainty that its biggest problem is in the querystring, you’re passing her, most likely thus:
request = function() {
$.ajax({
url: "https://requestb.in/1fzmwxx1",
type: "POST",
data: {
"acesso['KMEntrada']": 1000,
"acesso['HorarioSaida']": '2017-06-16 14:20:58',
"acesso['Status']": 0
},
success: function(returnjson) {},
error: function(returnjson) {}
});
}();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
See on requestb.in how the information arrives:
RAW BODY
Access%5B'Kminput'%5D=1000&access%5B'Timeout'%5D=2017-06-16+14%3A20%3A58&access%5B'Status'%5D=0
To see better:
RAW BODY URL ENCODED
access['Kmentrada']=1000&access['Horariosaida ']=2017-06-16 14:20:58&access['Status']=0
When all you had to do was pass like this:
RAW BODY
%5BKMEntrate%5D=1000&access%5BHorarioSaida%5D=2017-06-16+14%3A20%3A58&access%5BStatus%5D=0
RAW BODY URL ENCODED
access[Kminput]=1000&access[Scheduleleft]=2 017-06-16 14:20:58&access[Status]=0
What you did to access variables within the array $_POST['acesso']["'FrotaID'"]
works as a patch, a gambiarra, and not as a definitive solution, it is not recommended...
Because it wouldn’t be recommended?
If in the backend you, or some other developer by chance try to convert the $_POST
for an object, you will not be able to access the variables within the variable acesso
, see an example of what I mean:
$_POST["acesso"] = (object) Array( "'KMEntrada'" => 1000, "'HorarioSaida'" => '2017-06-16 14:20:58', "'Status'" => 0, "teste" => 540 );
$teste = (object) $_POST; // casting da variável
echo $teste ->acesso->teste // Imprime 540
echo $teste ->acesso->'KMEntrada' // invalido
If by chance you try to access json using javascript, you will also have a syntax error:
$arr = array(
"acesso" => array(
"'KMEntrada'" => 1000,
"'HorarioSaida'" => "2017-06-16 14:20:58",
"'Status'" => 0
)
);
$v = json_encode($arr);
echo "<script>";
echo "var a = ".$v.";";
echo "console.log(a.acesso);";
echo "console.log(a.acesso.'KMEntrada');";
echo "</script>";
Furthermore, I do not see any reasonable reason to pass a variable with special characters, if this statement is incorrect, I even ask you to correct me:
There is no context where it is valid to define a variable in a
queryString with special characters like quotes, arroba, dollar sign and so on, this could even cause problems when recovering variables passed in the backend.
Just know how you are sending this array to your backend and make the fix there, if it is by ajax for example:
request = function() {
$.ajax({
url: "https://requestb.in/1fzmwxx1",
type: "POST",
data: {
"acesso[KMEntrada]": 1000,
"acesso[HorarioSaida]": '2017-06-16 14:20:58',
"acesso[Status]": 0
},
success: function(returnjson) {},
error: function(returnjson) {}
});
}();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
See on requestb.in the information that arrives:
FORM/POST PARAMETERS
[Scheduleexit]: 2017-06-16 14:20:58
access[Status]: 0
access[Kminput]: 1000
RAW BODY
%5BKMEntrate%5D=1000&access%5BHorarioSaida%5D=2017-06-16+14%3A20%3A58&access%5BStatus%5D=0
This way, ai yes you can easily access the variables in the correct way, that would be $_POST['acesso']['KMEntrada']
echo $var['acesso']['KMEntrada']
that?– rray
I’ve tried it before, but it doesn’t work.
– user31040
Error appears?
– rray
Undefined index: Kmentrada
– user31040
That inside a for? by the way your code array is different from the question array.
– rray
I take this code array
print_r($_POST);
– user31040
Using the code you passed
echo($_POST['acesso']['KMEntrada']);
– user31040
Now it’s worked out... the code has to stay like this
echo($_POST['acesso']["'KMEntrada'"]);
– user31040