Skip to content

Instantly share code, notes, and snippets.

@meech-ward meech-ward/client.html Secret
Created Sep 16, 2019

What would you like to do?
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<form id="quoteForm">
<input type="text" name="quote">
<input type="submit" value="Submit">
<script src=""></script>
function createQuote(data) {
type: "POST",
url: "kanye.php",
data: data
}).then(data => {
}).catch(error => {
console.log("ERROR", error);
$("#quoteForm").on("submit", function(event) {
const data = $(this).serialize();
header("Content-type: application/json");
$quotes = [
"Pulling up in the may bike",
"If I don't scream, if I don't say something then no one's going to say anything.",
"I wish I had a friend like me",
"Style is genderless",
"Believe in your flyness...conquer your shyness.",
"Sometimes you have to get rid of everything"
$quote = $_POST["quote"];
$file = fopen("quote.txt", "w");
fwrite($file, $quote);
echo json_encode(["message" => "Successfully added quote"]);
} else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = array_rand($quotes);
$data = ["quote" => $quotes[$id]];
echo json_encode($data);
} else {
echo json_encode(["error" => "Method not supported"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.