2020-09-29

Sep 30 In-Class Exercise Thread.

Post your solutions to the Sep 30 IN-Class Exercise to this thread.
Best, Chris
Post your solutions to the Sep 30 IN-Class Exercise to this thread. Best, Chris
2020-09-30

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

-- Sep 30 In-Class Exercise Thread
<?php session_start(); ?>
<!DOCTYPE html> <html> <head> </head> <body>
    <h1>Shopping Cart</h1>
	<form method="post">
            <label>Shopping Cart Item</label>
	    <input type="text" name="item" placeholder="Cart Item" />
	    <input type="submit" value="Add" />
	</form>
<?php
    if (!empty($_POST['item'])) {
        $_SESSION = $_POST['item'];
        foreach($_SESSION as $item) {
				echo $item;
			}
    }
?> </body> </html>
(Edited: 2020-09-30)
<?php session_start(); ?> <!DOCTYPE html> <html> <head> </head> <body> <h1>Shopping Cart</h1> <form method="post"> <label>Shopping Cart Item</label> <input type="text" name="item" placeholder="Cart Item" /> <input type="submit" value="Add" /> </form> <?php if (!empty($_POST['item'])) { $_SESSION = $_POST['item']; foreach($_SESSION as $item) { echo $item; } } ?> </body> </html>

-- Sep 30 In-Class Exercise Thread
<?php session_start(); ?>
<!DOCTYPE html> <head>
    <title> </title>
</head> <body>
<form action="shopping.php" method="post">
    Shopping Cart Item: <input type="text" name="item">
<input type="submit" value="Add">
</form>
Your Item: <?php
    $_SESSION[] = $_POST['item'];
    if (!empty($_SESSION)) {
        foreach($_SESSION as $item) {
            echo $item;
        }
    }
?>
</body>
</html>
(Edited: 2020-09-30)
<?php session_start(); ?> <!DOCTYPE html> <head> <title> </title> </head> <body> <form action="shopping.php" method="post"> Shopping Cart Item: <input type="text" name="item"><br> <input type="submit" value="Add"> </form> Your Item: <?php $_SESSION[] = $_POST['item']; if (!empty($_SESSION)) { foreach($_SESSION as $item) { echo $item; } } ?> </body> </html>

-- Sep 30 In-Class Exercise Thread
<?php
    session_start();
    ?>
<!DOCTYPE html><html>
    <head></head>
    <body>
    
        <form action="blah.php" method="get">
            Shopping Cart: <input type="text" name="item">
            <input type="submit">
        </form>
        
        <?php
            if (!empty($_GET['item'])){
                $_SESSION[$_GET['item']] = $_GET['item'];
                foreach($_SESSION as $item){
                    echo "<h1>" . $item . "</h1>";
                }
            }
        ?>
    </body>
</html>
<?php session_start(); ?> <!DOCTYPE html><html> <head></head> <body> <form action="blah.php" method="get"> Shopping Cart: <input type="text" name="item"> <input type="submit"> </form> <?php if (!empty($_GET['item'])){ $_SESSION[$_GET['item']] = $_GET['item']; foreach($_SESSION as $item){ echo "<h1>" . $item . "</h1>"; } } ?> </body> </html>

-- Sep 30 In-Class Exercise Thread
Shopping Cart
Shopping Cart Item
(Edited: 2020-09-30)
<nowiki> <?php session_start(); ?> <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Shopping Cart</title> </head> <body> <div class=""> <form method="post" action="shopping.php"> <label for="shoppingcartitem">Shopping Cart Item</label> <input type="text" value="shoppingcartitem" /> <input type="submit" value="Add"/> </form> <?php $item = $_POST['shoppingcartitem']; $_SESSION[$item] = $item; if (!empty($_SESSION)) { echo "Currently in your cart:"; foreach ($_SESSION as $cartitem) { echo $cartitem; echo "<br>"; } } ?> </div> </body> </html> </nowiki>

-- Sep 30 In-Class Exercise Thread
Resource Description for Screen Shot 2020-09-30 at 4.47.31 PM.png
((resource:Screen Shot 2020-09-30 at 4.47.31 PM.png|Resource Description for Screen Shot 2020-09-30 at 4.47.31 PM.png))

-- Sep 30 In-Class Exercise Thread
<?php session_start(); ?> <html>
	<body>
		<form method="get">
		   <label> Shopping Cart Item </label>
		   <input type="text" name="item" id="item" />
		   <input type="submit" value="Add" />
		</form>
		<?php
			if (!isset($_SESSION['cart'])) {
				$_SESSION['cart'] = array();
			}
			$_SESSION['cart'][] = $_REQUEST['item'];
			if(!empty($_SESSION['cart'])) {
				foreach($_SESSION['cart'] as $item) {
					echo $item; echo "
"; } } ?> </body>
</html>
<?php session_start(); ?> <html> <body> <form method="get"> <label> Shopping Cart Item </label> <input type="text" name="item" id="item" /> <input type="submit" value="Add" /> </form> <?php if (!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); } $_SESSION['cart'][] = $_REQUEST['item']; if(!empty($_SESSION['cart'])) { foreach($_SESSION['cart'] as $item) { echo $item; echo "<br>"; } } ?> </body> </html>

-- Sep 30 In-Class Exercise Thread
Resource Description for 5.png
((resource:5.png|Resource Description for 5.png))

-- Sep 30 In-Class Exercise Thread
<pre>
    <?php
    session_start();
    // session_destroy();
    ?>
    <html>
    <head>
        <meta charset="utf-8">
        <title>HTML basics</title>
    </head>
    <body>
        <form method="POST">
            <label for="item">Shopping Cart Item:</label>
<input type="text" id="item" name="item">

<input type="submit" value="Add"> </form>
        <?php
            echo "CURRENT ITEMS: 
"; if(!empty($_REQUEST)){ $_SESSION[$_REQUEST["item"]] = $_REQUEST["item"]; } if (!empty($_SESSION)){ foreach ($_SESSION as $item) { echo $item. "
"; } } ?> </body>
    </html>
<pre>
(Edited: 2020-09-30)
<pre> <?php session_start(); // session_destroy(); ?> <html> <head> <meta charset="utf-8"> <title>HTML basics</title> </head> <body> <form method="POST"> <label for="item">Shopping Cart Item:</label><br> <input type="text" id="item" name="item"><br><br> <input type="submit" value="Add"> </form> <?php echo "CURRENT ITEMS: <br>"; if(!empty($_REQUEST)){ $_SESSION[$_REQUEST["item"]] = $_REQUEST["item"]; } if (!empty($_SESSION)){ foreach ($_SESSION as $item) { echo $item. "<br>"; } } ?> </body> </html> <pre>
[ Next ]
X