Skip to content

Instantly share code, notes, and snippets.

@kraigh
Created September 20, 2016 00:55
Show Gist options
  • Save kraigh/4097669fe06d2313f3781ae9b384ba0c to your computer and use it in GitHub Desktop.
Save kraigh/4097669fe06d2313f3781ae9b384ba0c to your computer and use it in GitHub Desktop.
<?php
if (!empty($_POST)) {
if (empty($_POST['name'])) {
$_POST['name'] = 'anonymous';
}
if (empty($_POST['greeted'])) {
$_POST['greeted'] = 'none';
}
if (empty($_POST['comments'])) {
$_POST['comments'] = 'none';
}
$data[] = $_POST;
$allResults = file_get_contents('results.json');
$tempArray = json_decode($allResults);
if (is_array($tempArray)) {
array_push($tempArray, $_POST);
} else {
$tempArray = $data;
}
$jsonData = json_encode($tempArray);
file_put_contents('results.json', $jsonData);
header("Location: http://kraigh.com/cse104/index.html?success=1");
die(1);
} else {
$jsonData = file_get_contents('results.json');
echo $jsonData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment