I previously had this code to take in data from a form and put it into a JSON file. It was working and after a few months I came back to my website and it began producing errors. The code below takes in the data and analyzes it for and if both are true, it will put that information in the JSON.
$postTitle =$_POST['postTitle'];
$postBody =$_POST['postBody'];
//pass
$postTitlePass ="no";
$postBodyPass ="no";
if(str_word_count($postTitle)>=1){
$postTitlePass ="yes";
}
if(str_word_count($postBody) >= 40){
$postBodyPass ="yes";
}
if($postTitlePass == "yes" && $postBodyPass == "yes"){
$postData = array('postTitle' => $postTitle,'postBody' => $postBody);
$inp = file_get_contents('data.json');
$tempArray = json_decode($inp);
$data = $postData;
array_push($tempArray, $data);
$jsonData = json_encode($tempArray, JSON_PRETTY_PRINT);
file_put_contents('data.json', $jsonData);
}