-- Mar 10 In-Class Exercise
<?php
//TAKEN FROM THE ZOOM CHAT
//StoreGold.php
function layout()
{
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>3/10/21 Ajay Salh</title>
</head>
<body>
<form method="post">
<label for="amount">Amount of Gold: </label>
<input type="text" id="amount" name = "amount" placeholder="Enter Amount of Gold Here" />
<button type="submit" name="store">Put Somewhere Safe</button>
</form>
</body>
</html>
<?php
}
if(isset($_POST['store'])) {
if(file_exists("gold.txt")) {
$gold = file_get_contents("gold.txt");
$gold = $_POST['amount'] + $gold;
file_put_contents("gold.txt", $gold);
} else {
$gold = $_POST['amount'];
file_put_contents("gold.txt", $gold);
}
header("Location:/SafeStorage.php");
}
layout();
//SafeStorage.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>3/10 Ajay Salh</title>
</head>
<body>
<h1> Total Gold Stored:
<?php
$gold = file_get_contents("gold.txt");
echo $gold;
?>
</h1>
</body>
</html>
<?php
//TAKEN FROM THE ZOOM CHAT
//StoreGold.php
function layout()
{
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>3/10/21 Ajay Salh</title>
</head>
<body>
<form method="post">
<label for="amount">Amount of Gold: </label>
<input type="text" id="amount" name = "amount" placeholder="Enter Amount of Gold Here" />
<button type="submit" name="store">Put Somewhere Safe</button>
</form>
</body>
</html>
<?php
}
if(isset($_POST['store'])) {
if(file_exists("gold.txt")) {
$gold = file_get_contents("gold.txt");
$gold = $_POST['amount'] + $gold;
file_put_contents("gold.txt", $gold);
} else {
$gold = $_POST['amount'];
file_put_contents("gold.txt", $gold);
}
header("Location:/SafeStorage.php");
}
layout();
//SafeStorage.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>3/10 Ajay Salh</title>
</head>
<body>
<h1> Total Gold Stored:
<?php
$gold = file_get_contents("gold.txt");
echo $gold;
?>
</h1>
</body>
</html>