problem writing to json file

+1 Marie Goodwyn · November 17, 2014
I am new at this so pardon my ignorance. I am trying to make a form to send data to a json file that will be later used to create a quiz with edge Animate. the quiz works fine with a json file I wrote. Now I want the teachers to be able to add questions to the json file from the form so they do not have to touch the json file.
I get the data posted to the html but not to the file.
Testing here:

Here is the code
if (!isset($_POST['params'])) {
        $params = $_POST['params'];
        $jsonObject = json_encode($params);
        file_put_content('myData.json', $jsonObject, FILE_APPEND);
echo '$jsonObject';


<script type="text/javascript">
     $(document).ready(function() {
         var postData = {
                question: $("#question").val(),
                answer1: $("#answer1").val(),
answer2: $("#answer2").val(),
answer3: $("#answer3").val(),
answer4: $("#answer4").val(),
correctAnswer: $("#correctAnswer").val(),
                image: $("#image").val(),
                feedbackInfo: $("#feedbackInfo").val()

var params = JSON.stringify(postData);
            type: "POST",
data: params, 
url: "submit.php",                  
            success: function (data) {
$("#myData").html("this data was posted: " + params);
error: function(e){


<form id="newQuestion" name="newQuestion" method="post">
<label for="question">Question:</label>
    <input id="question" name="question" type="text" /><br>
<label for="answer1">Answer 1 or distractor: </label>
    <input id="answer1" name="answer1" type="text" /><br>
<label for="answer">Answer 2 or distractor: </label>
    <input id="answer2" name="answer2" type="text" /><br>
<label for="answer">Answer 3 or distractor: </label>
    <input id="answer3" name="answer3" type="text"  /><br>
<label for="question">Answer 4 or distractor: </label><br>  
    <input id="answer4" name="answer4" type="text"  /><br>
<label for="correctAnswer">Correct answer number: </label>
    <input id="correctAnswer" name="correctAnswer" type="text" /><br> 
<label for="image">Image name (Exampe: for house.png simply enter: house): </label>
    <input id="image" name="image" type="text"  /> <br>
<label for="feedbackInfo">Info about the question: </label>
    <input id="feedbackInfo" name="feedbackInfo" type="text" /> <br>        
<input type="button" value="submit" name="submit" id="submit"/>  

Post a Reply


- page 3
Oldest  Newest  Rating
0 Marie Goodwyn · November 19, 2014
I am so ashamed I missed that! I help people with this kind of things in the Animate forum and here I missed it even though I looked at the code several times. I did think there was a variable issue though but since php is new to me I  guess my brain did not recognize it was not a variable.
0 Marie Goodwyn · November 19, 2014
I created a form to load the data from json. Here is the whole project again.
0 Marie Goodwyn · November 19, 2014
Wow, this is not only functional, it is also a very nice UI! How can I thank you? You did such a great job and I am totally humbled that you took the time to do all this for me.
0 Marie Goodwyn · November 19, 2014
You have really gone the extra mile to help a total stranger and I will not forget it. 

I still have to finish the php tutorial here and I will probably go through it several times until I can make things work on my own. I guess it will take some time. I am mostly self-taught and learned JavaScript here with Bucky. I have recommended it several time on the Animate forum.  I will also carefully review your input above.

As you, it is my privilege to help others on the Edge Animate forum and it is rewarding in itself to see how happy the people we help are. I have received countless emails of "happy customers" and it is always nice to get them. 

When someone thanks me on the forum, I often end my post with: "Now, go help someone else!"  and some do!

So I hope some day I will be able to answer a php question! Who knows...
-1 Marie Goodwyn · November 21, 2014
I tried FF and Chrome try to save the file, open the dialog box and fait. Safari and IE give a server error.

Here is what I have noticed looking at the server (godaddy) folders. The file is written at the root folder (testphp3) as Data\MyData.json.  and as you can see it is 583 bytes. However there is a file in the Data folder and it is 0 bytes. 

So I am thinking that something is wrong when the file is created and data is sent to it. 

-1 Marie Goodwyn · November 21, 2014
OK. I think the path is wrong using \ instead of / but even though I changed them in all the files I still cannot download.

The file cannot be found in the server. Is there an extra / in front?



Server-side, HTML embedded scripting language used to create dynamic Web pages.