[ Prev ]
2021-03-03

-- Mar 3 In-Class Exercise
 
 
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Add Me</title>
  </head>
  <body>
    <h2>Add Me</h2>
    <form method="post" action="addme.php">
      <label for="numbertoAdd">Number to Add: </label>
      <input type="number" name="numberToAdd" id="numberToAdd"  />
      <input type="submit" value="Submit">
    </form>
  </body>
</html> 
 
<?php
if (!is_file("current.txt")) {
  file_put_contents("current.txt", 0);
} 
 
$total = file_get_contents("current.txt"); 
 
if (isset($_POST["numberToAdd"])) {
  $total = $total + $_POST["numberToAdd"];
} 
 
echo "Total Added So far: $total"; 
 
file_put_contents("current.txt", $total);
?> 
 
(Edited: 2021-03-03)
<pre> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add Me</title> </head> <body> <h2>Add Me</h2> <form method="post" action="addme.php"> <label for="numbertoAdd">Number to Add: </label> <input type="number" name="numberToAdd" id="numberToAdd" /> <input type="submit" value="Submit"> </form> </body> </html> <?php if (!is_file("current.txt")) { file_put_contents("current.txt", 0); } $total = file_get_contents("current.txt"); if (isset($_POST["numberToAdd"])) { $total = $total + $_POST["numberToAdd"]; } echo "Total Added So far: $total"; file_put_contents("current.txt", $total); ?> </pre>

-- Mar 3 In-Class Exercise
 <?php 
 $file_handle = fopen("current.txt", "r");
 $num = fread($file_handle, filesize("current.txt"));
 fclose($file_handle);
 if(isset( $_POST['submit'])){
  $num += $_REQUEST['number'];
 }
 $fileHandle = fopen("current.txt", "w");
 fwrite($fileHandle, $num);
 fclose($fileHandle);
 ?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>In-Class Exercise: March 3</title>
 </head>
 <body>
  <form method="post" action="addme.php">
    <h1>Number to add</h1>
    <input type="text" name="number" />
    <input type="submit" name="submit" />
  </form>
  <h1>Total Added So Far: <?php echo $num ?></h1>
 </body>
 </html>
<?php $file_handle = fopen("current.txt", "r"); $num = fread($file_handle, filesize("current.txt")); fclose($file_handle); if(isset( $_POST['submit'])){ $num += $_REQUEST['number']; } $fileHandle = fopen("current.txt", "w"); fwrite($fileHandle, $num); fclose($fileHandle); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>In-Class Exercise: March 3</title> </head> <body> <form method="post" action="addme.php"> <h1>Number to add</h1> <input type="text" name="number" /> <input type="submit" name="submit" /> </form> <h1>Total Added So Far: <?php echo $num ?></h1> </body> </html>

-- Mar 3 In-Class Exercise
<html> <body>
    <?php $sum =0; ?>
<form method="post"> <Label for="number">Enter Number:</Label> <input type="number" name="number" />

<input type="submit" name="add" value="Add">
    </form>
    <?php
    if (isset($_POST['add'])){
    $myfile=fopen("current.txt", "a");
    $num1 = intval(file_get_contents("current.txt"));
    $num2= $_POST['number'];
    $sum= $num1+$num2;
    fwrite($myfile,$sum);
    fclose($myfile);
    echo $sum;
} ?> </body> </html>
<html> <body> <?php $sum =0; ?> <form method="post"> <Label for="number">Enter Number:</Label> <input type="number" name="number" /><br><br> <input type="submit" name="add" value="Add"> </form> <?php if (isset($_POST['add'])){ $myfile=fopen("current.txt", "a"); $num1 = intval(file_get_contents("current.txt")); $num2= $_POST['number']; $sum= $num1+$num2; fwrite($myfile,$sum); fclose($myfile); echo $sum; } ?> </body> </html>

-- Mar 3 In-Class Exercise
<!DOCTYPE html>
 <html>
 <head>
   <meta charset="utf-8"/>
 	<title>Form</title>
 </head>
 <body>
 
<form method="post" action="addme.php">
   <label for="num">Number to Add:</label>
   <input type="number"  name="Number to Add"/>
   <input type="submit" value="Add"/>
</form>
<p>Total Added So Far: <?php
   $file_name = 'current.txt'; 
   $count = 0;
   $count = file_get_contents($file_name);
   if (isset($_POST['Number to Add'])) {
      $count = $_POST['Number to Add'] + $count;
      file_put_contents($file_name, $count);
   }
   echo $count;
?> </p> </body> </html>
(Edited: 2021-03-03)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Form</title> </head> <body> <form method="post" action="addme.php"> <label for="num">Number to Add:</label> <input type="number" name="Number to Add"/> <input type="submit" value="Add"/> </form> <p>Total Added So Far: <?php $file_name = 'current.txt'; $count = 0; $count = file_get_contents($file_name); if (isset($_POST['Number to Add'])) { $count = $_POST['Number to Add'] + $count; file_put_contents($file_name, $count); } echo $count; ?> </p> </body> </html>

-- Mar 3 In-Class Exercise
<!DOCTYPE html> <html>
	<head>
		<title>Add Me</title>
	</head>
	<body> 
		<form action="addme.php" method="post">
		    <label for="num">Number to Add:</label>
		    <input type="number" id="num" name="num">
		    <input type="submit" value="Submit">
		</form>
		<div>Total Added So Far: 
		<?php
		$file_name = 'current.txt'; 
		$num = 0;
		if (file_exists($file_name)) {
		    $num = file_get_contents($file_name);
		}
		if (isset($_POST['num'])) {
		    $num = $_POST['num'] + $num;
		    file_put_contents($file_name, $num);
		}
		echo $num;
		?>	
		</div>
	</body>
</html>
<!DOCTYPE html> <html> <head> <title>Add Me</title> </head> <body> <form action="addme.php" method="post"> <label for="num">Number to Add:</label> <input type="number" id="num" name="num"> <input type="submit" value="Submit"> </form> <div>Total Added So Far: <?php $file_name = 'current.txt'; $num = 0; if (file_exists($file_name)) { $num = file_get_contents($file_name); } if (isset($_POST['num'])) { $num = $_POST['num'] + $num; file_put_contents($file_name, $num); } echo $num; ?> </div> </body> </html>

-- Mar 3 In-Class Exercise
<!DOCTYPE html> <html>
  <body>
    <p>Current Total: </p>
    <?php
    $total = 0;
    $file_name = 'current.txt';
    if (file_exists($file_name){
        $total = file_get_contents($file_name);
    }
    if (isset($_POST['Add'])) {
        $total += $_POST['num'];
        file_put_contents($file_name, $total);
    }
    echo $total;
    ?>    
    <form action="addme.php" method="post">
    <label for = "num">Number: </label>
    <input type="number" id="num" min="0">
    <input type="submit" value="Add">
    </form>  
  </body>
</html>
<!DOCTYPE html> <html> <body> <p>Current Total: </p> <?php $total = 0; $file_name = 'current.txt'; if (file_exists($file_name){ $total = file_get_contents($file_name); } if (isset($_POST['Add'])) { $total += $_POST['num']; file_put_contents($file_name, $total); } echo $total; ?> <form action="addme.php" method="post"> <label for = "num">Number: </label> <input type="number" id="num" min="0"> <input type="submit" value="Add"> </form> </body> </html>

-- Mar 3 In-Class Exercise
<?php
$temp = fopen("temp.txt", "a");
$added = intval(file_get_contents("temp.txt"));
if (isset($_POST['AddButton'])) {
    $added = $added + intval($_POST['input']);
    file_put_contents("temp.txt", strval($added));
} 
?> 
 
<!doctype html>
<html>
<head>
<title>Add a Number</title>
</head>
<body>
<form action="" method="post">
    <input type="text" name="input" placeholder="Enter a number" />
    <input type="submit" name="AddButton" value="Add" />
    <p><?php echo "Total added: ".$added; ?></p>
</form>   
</body>
</html> 
 
<pre> <?php $temp = fopen("temp.txt", "a"); $added = intval(file_get_contents("temp.txt")); if (isset($_POST['AddButton'])) { $added = $added + intval($_POST['input']); file_put_contents("temp.txt", strval($added)); } ?> <!doctype html> <html> <head> <title>Add a Number</title> </head> <body> <form action="" method="post"> <input type="text" name="input" placeholder="Enter a number" /> <input type="submit" name="AddButton" value="Add" /> <p><?php echo "Total added: ".$added; ?></p> </form> </body> </html> </pre>

-- Mar 3 In-Class Exercise
<!DOCTYPE html>
<html lang="en"> 
 
<head>
    <meta charset="UTF-8">
    <title>Add Me Program: Emily Chan</title>
</head> 
 
<body>
    <?php 
        $sum = 0;
        $file_sum = "current.txt";
    ?> 
 
    <form method="post" action="addme.php">
        <label for="num">Number to Add:</label>
        <input type="number" name="number" size="5" />
        
        <input type="submit" name="add" value="Add" /> 
 
    <?php
        if (isset($_POST['add'])){
            $sum;
            $entered = $_POST['number'];
            
            if(file_exists($file_sum)){
                $prev = intval(file_get_contents($file_sum));
            }
            else{
                fopen($file_sum, 'w') or exit("Unable to open current.txt");
            }
            
            $sum = $entered + $prev;
        }
    ?>
        
        <label>Total Added So Far:             <?php                 echo $sum;             ?>                  </label>            <?php             file_put_contents($file_sum, strval($sum));             fclose($file_sum);         ?>     </form> </body>    </html>
<pre> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add Me Program: Emily Chan</title> </head> <body> <?php $sum = 0; $file_sum = "current.txt"; ?> <form method="post" action="addme.php"> <label for="num">Number to Add:</label> <input type="number" name="number" size="5" /> <input type="submit" name="add" value="Add" /> <?php if (isset($_POST['add'])){ $sum; $entered = $_POST['number']; if(file_exists($file_sum)){ $prev = intval(file_get_contents($file_sum)); } else{ fopen($file_sum, 'w') or exit("Unable to open current.txt"); } $sum = $entered + $prev; } ?> <br> <label>Total Added So Far: <?php echo $sum; ?> </label> <?php file_put_contents($file_sum, strval($sum)); fclose($file_sum); ?> </form> </body> </html> </pre>

-- Mar 3 In-Class Exercise
Number to Add: Add

Total Added So Far:

(Edited: 2021-03-03)
<nowiki> <!DOCTYPE html> <html> <head> </head> <body> <form method="post" action="addme.php"> <label>Number to Add: </label> <input type="text" name="num" placeholder="Enter number" /> <button type="submit" name="Add">Add</button> </form> <?php $val = 0; if (file_exists("current.txt")) { $curr = intval(file_get_contents("current.txt")); $num = $_POST['num']; $val = $num + $curr; file_put_contents("current.txt", $val); } else { $num = $_POST['num']; $val = $val + $num; file_put_contents("current.txt", $val); } ?> <p>Total Added So Far: <?php echo $val ?> </p> </body> </html></nowiki>

-- Mar 3 In-Class Exercise
 <!DOCTYPE html>
 <html>
 <head>
 	<meta charset="utf-8"/>
 	<title>Ajay Salh</title>
 </head>
 <body>
 	<form method="post" action="addme.php">
		<label for="num">Number to Add: </label>
		<input type="number" id="num" name="num" placeholder="Enter A Number" />
		<button type="submit" name="add">Add</button>
		</br><button type = "submit" name ="reset">Reset to Zero</button>
   	</form>
   	<?php
   		$a = intval(file_get_contents("current.txt"));
   		if (isset($_POST['add'])) {
   			$a = $_POST['num'] + $a;
   			file_put_contents("current.txt", strval($a));
   		}
   		if (isset($_POST['reset'])) {
			$a = 0;
			file_put_contents("current.txt", strval($a));
		}
   	?>
   	</br><p> Total Added So Far: <?= $a; ?></p>
 </body>
 </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Ajay Salh</title> </head> <body> <form method="post" action="addme.php"> <label for="num">Number to Add: </label> <input type="number" id="num" name="num" placeholder="Enter A Number" /> <button type="submit" name="add">Add</button> </br><button type = "submit" name ="reset">Reset to Zero</button> </form> <?php $a = intval(file_get_contents("current.txt")); if (isset($_POST['add'])) { $a = $_POST['num'] + $a; file_put_contents("current.txt", strval($a)); } if (isset($_POST['reset'])) { $a = 0; file_put_contents("current.txt", strval($a)); } ?> </br><p> Total Added So Far: <?= $a; ?></p> </body> </html>
[ Next ]
X