Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Session code found at https://code.tutsplus.com/tutorials/build-a-shopping-cart-with-php-and-mysql--net-5144
- session_start();
- ?>
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" type="text/css" href="stylesheet.css">
- <title>Ross' Mug Shop</title>
- </head>
- <body>
- <nav>
- <h1>
- Ross' Mug Shop
- </h1>
- <ul>
- <li><a href="index.php">View Home Page</a></li>
- </ul>
- </nav>
- </body>
- <code>
- <?php
- $server="csmysql.cs.cf.ac.uk";
- $user="c1615528";
- $password="";
- $database="c1615528";
- $mugTable="SELECT * FROM Mugs";
- $connect = new mysqli($server, $user, $password, $database);
- $result= $connect->query($mugTable);
- if(isset($_GET['action']) && $_GET['action'] == "add") {
- $mugName = $_GET['id'];
- if (isset($_SESSION['cart'][$mugName])) {
- $_SESSION['cart'][$mugName]['quantity'] ++;
- }
- else {
- $selectMug="SELECT * FROM Mugs WHERE mugName={$mugName}";
- $query_s=$connect->query($selectMug);
- $row_s=$query_s->fetch_array();
- $_SESSION['cart'][$row_s['mugName']]=array(
- "quantity" => 1,
- "price" => $row_s['mugPrice']
- );
- }
- }
- $mugName2 = $_GET['id'];
- $getMug = "SELECT * FROM Mugs WHERE mugName={$mugName2}";
- $query=$connect->query($getMug);
- $mug=$query->fetch_array();
- ?>
- </code>
- <body>
- <?php
- $mugName3 = $mug['mugName'];
- $mugPrice = $mug['mugPrice'];
- $mugImage = $mug['mugImage'];
- $mugDesc = $mug['mugDescription'];
- ?>
- <div class="productImage"><img src="<?php echo $mugImage ?>" width="100" height="100"></div>
- <div class="productName"><?php echo $mugName3 ?></div>
- <div class="productPrice">£<?php echo $mugPrice ?></div>
- <div class="productDesc"><?php echo $mugDesc ?></div>
- <div><a href="index.php?page=index&action=add&id=<?php echo $mugName3 ?>">Add to cart</a></div>
- <?php
- // Close the connection
- mysqli_close($con);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement