32 lines
578 B
PHP
32 lines
578 B
PHP
<?php
|
|
|
|
# Define Inital Variables
|
|
$fname = htmlspecialchars($_POST["fname"]);
|
|
$fmsg = htmlspecialchars($_POST["fmessage"]);
|
|
$savemsg = array("name" => $fname, "message" => $fmsg);
|
|
|
|
|
|
|
|
|
|
# Setup JSON
|
|
$data = json_decode(file_get_contents('test.json'), true);
|
|
|
|
|
|
# Add
|
|
array_unshift($data , $savemsg);
|
|
|
|
# Check name and message
|
|
if ($fname == "") {
|
|
echo "There is no name, Try again with a name";
|
|
exit();
|
|
}
|
|
if ($fmsg == "") {
|
|
echo "There is no message, Try again with a message";
|
|
exit();
|
|
}
|
|
|
|
file_put_contents('test.json', json_encode($data, JSON_PRETTY_PRINT));
|
|
|
|
echo $fmsg;
|
|
|