更新:所有值現在都返回「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