2016-03-24 3 views
-3

私はHTMLフォームを持っています。入力をJSON形式の外部ファイルに保存する必要があります。HTMLフォームデータはJSONとして保存されます

次のように私は通信のphpファイルを持っている:

$formdata=array(
    'name' => $_POST['name'], 
    'contact' => $_POST['contact'], 
    'email' => $_POST['email'], 
    'date' => $_POST['date'], 
    'size' => $_POST['size'], 
    'special-comment' => $_POST['special-comment'] 
); 

$jsonformat = json_encode($formdata); 

$save = fopen("reserveOnlineJason.php", "a"); 
fwrite($save, $jsonformat); 
fclose($save); 
echo "Form Submitted !!! Lets to back"; 

私のフォーム入力は以下の通りreserveOnlineJason.phpに行く:私のような適切なJASON形式でそれらを得るのですか

{"name":"fah","contact":"7899874545","email":"[email protected]","date":"2016-03-16","size":"50","special-comment":"corner"} 
{"name":"rah","contact":"7899874545","email":"[email protected]","date":"2016-03-16","size":"50","special-comment":"corner"} 

[{"name":"far","contact":"7899874545","email":"[email protected]","date":"2016-03-16","size":"50","special-comment":"corner"},{"name":"rah","contact":"7899874545","email":"[email protected]","date":"2016-03-16","size":"50","special-comment":"corner"}] 

または、

{"info": [{"name":"far","contact":"7899874545","email":"[email protected]","date":"2016-03-16","size":"50","special-comment":"corner"},{"name":"rah","contact":"7899874545","email":"[email protected]","date":"2016-03-16","size":"50","special-comment":"corner"}]} 
+0

投稿の間にコンマはありません。彼らは次のようになります: {a、s、d、d、f、g} {d、e、r、t、y、u} 私はそれが[ {{a、s、d、d、f、g}、{d、e、r、t、y、 u}]} – farah

+0

最初の配列内に追加の配列を出力する必要があります。 –

答えて

-1

このように使用できます。

<?php 
     $formdata= array(
       array(
        'name' => $_POST['name'], 
        'contact' => $_POST['contact'], 
        'email' => $_POST['email'], 
        'date' => $_POST['date'], 
        'size' => $_POST['size'], 
        'special-comment' => $_POST['special-comment'] 
      )); 
?> 

したがって、json_encodeはオブジェクトを提供します[{..}}。

参照:https://eval.in/542026

関連する問題