[ Prev ]
2020-09-30

-- Sep 30 In-Class Exercise Thread
<?php session_start();?> <!DOCTYPE html>
 <html>
 <head>
 </head>
 <body>
    <h1>Shopping Cart</h1>
	   <form method="get">
       <label>Shopping Cart Item</label>
	     <input type="text" name="item" placeholder="Cart Item"/>
       <input type="submit" name="submit" value="Add" />
	</form>
  <p>Your Item:</p>
<?php
  $_SESSION['item'];
  if(empty($_SESSION['item'])){
    $_SESSION['item'] = [];
  }
  if(isset($_GET['submit'])) {
      array_push($_SESSION['item'], $_GET['item']);
   }
 	if (!empty($_SESSION['item'])) {
      foreach ($_SESSION['item'] as $items) {
        echo $items. "
"; } } ?>
</body> </html>
<?php session_start();?> <!DOCTYPE html> <html> <head> </head> <body> <h1>Shopping Cart</h1> <form method="get"> <label>Shopping Cart Item</label> <input type="text" name="item" placeholder="Cart Item"/> <input type="submit" name="submit" value="Add" /> </form> <p>Your Item:</p> <?php $_SESSION['item']; if(empty($_SESSION['item'])){ $_SESSION['item'] = []; } if(isset($_GET['submit'])) { array_push($_SESSION['item'], $_GET['item']); } if (!empty($_SESSION['item'])) { foreach ($_SESSION['item'] as $items) { echo $items. "<br>"; } } ?> </body> </html>
2020-10-02

-- Sep 30 In-Class Exercise Thread
<?php 
    session_name("sessID");
    session_start();
?>
<form>
    <label for="item">Item:</label><br />
    <input type="text" id="item" name="item" placeholder="Enter item here" /><br />
    <input type="submit" id="submit" name="submit" value="Submit" />
</form>
<?php
    if (!empty($_REQUEST[item])) $_SESSION["cart"][] = $_REQUEST[item];
    foreach ($_SESSION["cart"] as $i) echo "$i<br />";
I'm assuming we don't need to do all the extra HTML stuff like <head> and what not, since it's just an exercise and it works fine without
<pre> <?php session_name("sessID"); session_start(); ?> <form> <label for="item">Item:</label><br /> <input type="text" id="item" name="item" placeholder="Enter item here" /><br /> <input type="submit" id="submit" name="submit" value="Submit" /> </form> <?php if (!empty($_REQUEST[item])) $_SESSION["cart"][] = $_REQUEST[item]; foreach ($_SESSION["cart"] as $i) echo "$i<br />"; </pre> I'm assuming we don't need to do all the extra HTML stuff like <head> and what not, since it's just an exercise and it works fine without

-- Sep 30 In-Class Exercise Thread
<?php session_start(); ?> <!DOCTYPE html> <html>
    <head>
        <title>Shopping Cart</title>
        <meta charset= "UTF-8">
    </head>
    <body>
        <div class = "shopping cart">
            <form method = "get" action = "shopping.php">
                <label for= "item">Shopping Cart Item</label>:    
                <input id = "item" name = "item" type = "text">
                <input type = "submit" name = "submit button" value = "add">
            </form>
        </div>
  Items:<?php
            $_SESSION[$_REQUEST["item"]] = $_REQUEST["item"];
            if(!empty($_SESSION))
            {
                foreach($_SESSION as $item)
                {
                    echo $item. " ";
                }
            }
            
        ?>
    </body>
</html>
<?php session_start(); ?> <!DOCTYPE html> <html> <head> <title>Shopping Cart</title> <meta charset= "UTF-8"> </head> <body> <div class = "shopping cart"> <form method = "get" action = "shopping.php"> <label for= "item">Shopping Cart Item</label>: <input id = "item" name = "item" type = "text"> <input type = "submit" name = "submit button" value = "add"> </form> </div> Items:<?php $_SESSION[$_REQUEST["item"]] = $_REQUEST["item"]; if(!empty($_SESSION)) { foreach($_SESSION as $item) { echo $item. " "; } } ?> </body> </html>
2020-10-04

-- Sep 30 In-Class Exercise Thread
<?php session_start(); ?> <!DOCTYPE html> <html>
  <head>
    <title>Shopping</title>
      <body>
        <form method="get">
          <label for="shop">Shopping Cart 
</label> <input type="text" name="shop" id= "shop"> <input type="submit" name="Add"/> <label>Shopping List</label>
</form>
<?php $_SESSION['shop'][] = $_REQUEST['shop']; if (!empty($_SESSION['shop'])) {
  foreach($_SESSION['shop'] as $shop) {
    echo $shop;
    echo "
"; } }
  ?>
  </body>
  </html>
<?php session_start(); ?> <!DOCTYPE html> <html> <head> <title>Shopping</title> <body> <form method="get"> <label for="shop">Shopping Cart <br/></label> <input type="text" name="shop" id= "shop"> <input type="submit" name="Add"/> <label>Shopping List</label> <br/> </form> <?php $_SESSION['shop'][] = $_REQUEST['shop']; if (!empty($_SESSION['shop'])) { foreach($_SESSION['shop'] as $shop) { echo $shop; echo "<br>"; } } ?> </body> </html>
2020-10-05

-- Sep 30 In-Class Exercise Thread
<?php session_start() ?> <!DOCTYPE html> <html> <head>
	<title>September 30 in class exercise</title>
</head> <body>
	<form method="get">
		<label for="item">Your Shopping Cart:</label>
		<input type="text" name="theItem" id="theItem">
		<input type="submit" name="Submit">
	</form>
	<?php
		$_SESSION = $_REQUEST['theItem']
		if (!empty($_SESSION)) {
			foreach($_SESSION as $item) {
				echo $item
			}
		}
 
</body> </html>
<?php session_start() ?> <!DOCTYPE html> <html> <head> <title>September 30 in class exercise</title> </head> <body> <form method="get"> <label for="item">Your Shopping Cart:</label> <input type="text" name="theItem" id="theItem"> <input type="submit" name="Submit"> </form> <?php $_SESSION = $_REQUEST['theItem'] if (!empty($_SESSION)) { foreach($_SESSION as $item) { echo $item } } </body> </html>
X