if(file_exists("gold.txt")) { $goldNum = file_get_contents("gold.txt"); if(isset($_REQUEST['goldAmount'])) { $goldNum = $goldNum + $_REQUEST['goldAmount']; } file_put_contents("gold.txt", $goldNum); } else { file_put_contents("gold.txt",0); } header("Location:SafeStorage.php");} ?>
<head> <meta charset="utf-8"/> <title>Store Gold</title> </head> <body> <form method="post" action="SafeStorage.php"> <label for="text"> Amount of Gold:</label> <input type="number" name="goldAmount" id="amount"/> <input type="submit" name='submit button' value='Put Somewhere Safe' /> </form> </body></html>
<head> <meta charset="utf-8"/> <title>SafeStorage</title> </head> <body> <p>Total Gold Stored: <?php if(!file_exists("gold.txt")){ echo file_get_contents("gold.txt") } ?> </p>
</body></html>
StoreGold.php <?php if(isset($_REQUEST["numGold"])){ if(!file_exists("gold.txt")){ file_put_contents("gold.txt", 0); }//if else{}//else $numGold = $_REQUEST["numGold"]+file_get_contents("gold.txt"); file_put_contents("gold.txt", $numGold); }//if else{}//else header("Location:SafeStorage.php"); ?> <!DOCTYPE html><html> <head> <title>exercise mar 10- store gold</title> <meta charset="utf-8" /> </head> <body> <form method="post" action=""> <label for="gold">Amount of Gold: </label> <input type="text" name="numGold" id="numGold" /> <input type="submit" value="Put Somewhere Safe" /> </form> </body> </html> <?php SafeStorage.php <?php $totalGold; if(file_exists("gold.txt")){ $totalGold = file_get_contents("gold.txt"); }//if else{}//else ?> <!DOCTYPE html><html> <head> <title>exercise mar 10- safe storage</title> <meta charset="utf-8" /> </head> <body> <p> Total Gold Stored: <?php echo $totalGold ?></p> </body> </html> <?php(Edited: 2021-03-12)
<?php fopen("gold.txt", "a"); $gold = intval(file_get_contents("gold.txt")); if (isset($_POST['AddButton'])) { $gold = $gold + intval($_POST['input']); file_put_contents("gold.txt", strval($gold)); header("Location:./SafeStorage.php"); } ?> <!doctype html> <html> <head> <title>Gold Storage</title> </head> <body> <form method="post"> <input type="text" name="input" placeholder="Amount of Gold" /> <input type="submit" name="AddButton" value="Put Somewhere Safe" /> </form> </body> </html>
<?php fopen("gold.txt", "a"); $gold = intval(file_get_contents("gold.txt")); ?> <!doctype html> <html> <head> <title>Gold Storage</title> </head> <body> <p><?php echo "Total Gold Stored: ".$gold; ?></p> </body> </html>
<?php if(isset($_POST["aGold"])) { $data = $_POST["aGold"]; $fp = fopen("gold.txt", "a+"); $gold = fgets($fp); $gold = $gold + $data; file_put_contents("gold.txt", ""); fwrite($fp, $gold); fclose($fp); header("Location:SafeStorage.php"); } ?> <!DOCTYPE html> <html lang="en-US"> <head> <title>Gold Store Page</title> <meta name="description" content="Gold Storage"> <meta name="author" content="Mark Silva"> <meta charset="utf-8"> </head> <body> <h1>Store Gold</h1> <form name="goldForm" method="post"> <label for="aGold">Amount of Gold:</label> <input type="text" id="aGold" name="aGold">
<input type="submit" value="Put Somewhere Safe"> </form> </body> </html>
<!DOCTYPE html> <html lang="en-US"> <head> <title>Storage Gold</title> <meta name="description" content="Storage Gold"> <meta name="author" content="Mark Silva"> <meta charset="utf-8"> </head> <body> <h1>Amount of Gold Stored</h1> <?php $fp = fopen("gold.txt", "r+"); $gold = fgets($fp); fclose($fp); ?> <p> Total <?= $gold ?> </p> </body> </html>
StoreGold.php: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Store Gold</title> </head> <body> <h2>Store Gold</h2> <form method="post"> <label for="amountOfGold">Amount of Gold: </label> <input type="number" name="amountOfGold" id="amountOfGold" /> <input type="submit" value="Put Somewhere Safe"> </form> </body> </html> <?php header("Location:SafeStorage.php"); if (isset($_POST["amountOfGold"])) { if (!is_file("gold.txt")) { file_put_contents("gold.txt", 0); } $amountOfGold = file_get_contents("gold.txt") + $_POST["amountOfGold"]; file_put_contents("gold.txt", $amountOfGold); } ?> SafeStorage: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Safe Storage</title> </head> <body> <h2>Safe Storage</h2> <p>Total Gold Stored: <?php echo file_get_contents("gold.txt") ?></p> </body> </html>(Edited: 2021-03-14)
$gold = $gold + intval($_POST['input']); file_put_contents("gold.txt", strval($gold)); header("Location:SafeStorage.php");} ?>
<title>Gold Storage</title></head>
<form method="post"> <input type="text" name="input" /> <input type="submit" name="button" value="Put Somewhere Safe" /> </form></body>
<title>Gold Storage</title></head>
<p><?php echo "Total Gold Stored: " . $gold; ?></p></body>
Gold in storage:
<body> <?php $total = 0; $file_name = 'gold.txt'; if (file_exists($file_name)){ $total = file_get_contents($file_name); } if (isset($_REQUEST['num'])) { $total = $_REQUEST['num'] + $total; file_put_contents($file_name, $total); } if(isset($_POST['submit'])){ header("Location:SafeStorage.php"); } ?> <form action="" method="post"> <label for = "num">Amount of Gold: </label> <input type="number" id="num" name="num" min="0"> <input type="submit" name="submit" value="Put Somewhere Safe"/> </form>
</body></html>
<body> <p>Total Gold Stored: <?php $total = 0; $file_name = 'gold.txt'; if (file_exists($file_name)){ $total = file_get_contents($file_name); } echo $total; ?> </p> </body></html>
<form action="" method = 'post'> <label >Amount of Gold</label> <input type="number" name="amount"> <input type="submit" name='submit' value="Put Somewhere Safe"> </form>
<?php if (isset($_POST['submit'])) { $data= $_POST['amount']; file_put_contents("gold.txt",$data); header("Location: safestorage.php"); } ?>
<?php require_once('storegold.php'); ?> <p> Total Gold Stored <?php echo readfile("gold.txt"); ?></p>