[ Prev ]
2021-03-15

-- 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>

-- Mar 10 In-Class Exercise
<!DOCTYPE html> <html>
  <body>
    <form action="GoldStorage" method="post">
      <label for="amount">amount to desposit: </label> 
      <input type="submit" name="depo" value="Deposit"/>
      <input type="number" id="amount" name="amount" min="0"> Gold   
    </form>
    <?php
    $money = 0;
    $file = 'goldstorage.txt';
    if(isset($_POST['submit'])
    {
      if (file_exists($file)){
        $total = file_get_contents($file_);
      }
    }
    if (isset($_REQUEST['amount'])) {
        $money = $_REQUEST['amount'] + $money;
        file_put_contents($file, $money);
    }
    }?>
  </body>
</html>
<!DOCTYPE html> <html>
  <body>
    <p>Gold held in bank storage: 
    <?php
    $amount = 0;
    if (file_exists('goldstorage.txt')){
        $amount = file_get_contents('goldstorage.txt');
    }
    echo $total;?>
    </p>
  </body>
</html>
<!DOCTYPE html> <html> <body> <form action="GoldStorage" method="post"> <label for="amount">amount to desposit: </label> <input type="submit" name="depo" value="Deposit"/> <input type="number" id="amount" name="amount" min="0"> Gold </form> <?php $money = 0; $file = 'goldstorage.txt'; if(isset($_POST['submit']) { if (file_exists($file)){ $total = file_get_contents($file_); } } if (isset($_REQUEST['amount'])) { $money = $_REQUEST['amount'] + $money; file_put_contents($file, $money); } }?> </body> </html> <!DOCTYPE html> <html> <body> <p>Gold held in bank storage: <?php $amount = 0; if (file_exists('goldstorage.txt')){ $amount = file_get_contents('goldstorage.txt'); } echo $total;?> </p> </body> </html>
X