I have problem, that i want to get variable $_POST
to add to value of an array. Then i will encode it to json. but the $_POST
variable didn't give any value. EDIT i did edit the codes: Here my codes:
<?php
$temp = isset($_POST['temp']) ? $_POST['temp'] : '';
$arr["temp_display"] = $temp;
echo json_encode($arr);
and i hope the result will be like this
{"temp_display": value_of_$temp}
I try to use same case but I add the value of $_POST to MySQL database and its Works. Here the code:
<?php
include("connect.php");
$link=Connection();
$temp=$_POST["temp"];
$query = "INSERT INTO `templog` (`temperature`)
VALUES ('".$temp."')";
mysql_query($query,$link);
mysql_close($link);
?>
EDIT Here my jquery code:
$(document).ready(function() {
setInterval( update, 200);
function update(){
var cache = $('.deneme').children();
$.getJSON('json.php', function(data) {
$('.deneme').text(data.temp).append(cache);
})
}
});
Thank you for Ur help...
In the first code block this line $temp=$_POST["temp"];
is unnecessary as you have done the same thing in the previous line. You can try by displaying the json data using var_dump
method like this:
echo "<pre>";
var_dump(json_encode('$arr');
echo "</pre>";
<?php
$temp = isset($_POST['temp']) ? $_POST['temp'] : '';
$arr["temp_display"] = $temp;
echo json_encode($arr);
?>