更新:所有值现在都返回“A”时,他们应该都是不同的值。 我想要做的是,通过邮寄请求发送一个值表到我的网站,该网站将表格数据保存到一个文本文件。我终于有了它,所以整个表打印到文本文件,但所有的值是A.我做错了什么?顺便说一下,我尝试了很多方法和许多其他“类似问题”,但都没有为我工作。提前致谢。PHP json_encode()返回空值
CODE:
<?php
$foo = file_get_contents("php://input");
$stuff = json_decode($foo, true);
function createtxt($cttext, $location,$stuff)
{
$ccontent = $cttext;
if (file_exists($location)) {
echo "The file $ffilename exists";
} else {
$fp = fopen($location, "wb");
fclose($fp);
$formdata = array(
'user'=> $cttext['user'],
'secretkey'=> $cttext['secretkey'],
'isanadmin'=> $cttext['isa'],
'firsttime'=> $cttext['firsttime'],
'display'=> $cttext['dis'],
'test'=> $cttext['test'],
'test2'=> $cttext['test2'],
'type'=> $cttext['type']
);
$jsondata = json_encode($formdata);
file_put_contents($location, $jsondata);
echo 'Created User Text File Named "data.txt" ';
}
}
function lookforuser($NAME,$stuff)
{
if (!file_exists('users/' . $NAME))
mkdir('users/' . $NAME);
echo 'User Folder Created ';
createtxt($NAME, 'users/' . $NAME . '/data.txt',$stuff);
}
lookforuser($stuff['user'],$stuff);
?>
输出文本文件:
{"user":"A","secretkey":"A","isanadmin":"A","firsttime":"A","display":"A","test":"A","test2":"A","type":"A"}
解决! 现在输出为: {“user”:“ASCORE”,“secretkey”:“secretkeytheyentered”,“isanadmin”:“0”,“firsttime”:“1”,“display”:“0” test“:”Works!“,”test2“:”Works!“,”type“:”0“} 更新所有$ cttext []为$ stuff [] n更新脚本 – ASCORE