Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <?php //All kod ligger i denna pastebin
- include("func.php");
- session_start();
- $link = mysqli_connect('127.0.0.1:3306', '970414', '970414');
- if (!$link) {
- die('Could not connect: ' . mysql_error());
- }
- mysqli_select_db($link, "db970414");
- /*
- if(isset ($_POST["add_to_cart"])){
- echo "Add to cart is set";
- if(isset ($_SESSION["shopping_cart"])){
- $idProd = $_POST["hidden_id"];
- if(isset($_POST["add_to_cart"])){
- addToCart($link, $idProd);
- $count = count($_SESSION["shopping_cart"]);
- $Products_array = array(
- 'idProducts' => $_POST["hidden_id"],
- 'Products_name' => $_POST["hidden_name"],
- 'Products_Price' => $_POST["hidden_price"]
- );
- $_SESSION["shopping_cart"][$count] = $Products_array; // Lägger till vara i varukorgen
- }
- else{
- $Products_array = array(
- 'idProducts' => $_POST["hidden_id"],
- 'Products_name' => $_POST["hidden_name"],
- 'Products_Price' => $_POST["hidden_price"]
- );
- $_SESSION["shopping_cart"][0] = $Products_array;// Lägger till första varan i varukorgen
- }
- }
- }*/
- ?>
- <html>
- <script src="script.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"> </script>
- <link rel="stylesheet" href="style.css">
- <head> <title>Spelbutik Norra</title> </head>
- <body>
- <H1 class="head">Spelbutik Norra</H1> <br>
- <div class="dropdown">
- <button class="dropbutton" onclick="toggleLoginDropDown()">
- Logga in
- </button>
- <div class="dropdown-content" id="loginDropdown" >
- <form action="func.php" method="post">
- Användarnamn: <input type="text" name="username"><br>
- Lösenord:<br> <input type="password" name="userpassword"><br>
- <input type="submit" value="Logga in">
- </form>
- </div>
- <button class="dropbuttonVaru" onclick="toggleCartDropDown()">Varukorg</button>
- <div class="dropdown-content-varu" id="cartDropdown" >
- </div>
- </div>
- <!-- <div class="grid-container">-->
- <div id="base">
- <?php
- $prodResult = mysqli_query($link, "SELECT * FROM Products");
- if (mysqli_num_rows($prodResult) > 0) {
- $count = 0;
- $prodId[] = array();
- $Price[] = array();
- $Name[] = array();
- $picture[] = array();
- while($row = mysqli_fetch_assoc($prodResult)) {
- /*echo "id: " . $row["idProducts"];*/
- $Price[$count] = $row["Price"];
- $Name[$count] = $row["Name"];
- $Picture[$count] = $row["Picture"];
- $prodId[$count] = $row["idProducts"];
- $count = $count + 1;
- }
- ?>
- <div id="Prod">
- <form method="post" action="index.php?action=add&id=<?php echo $prodId[0]?>">
- <img src=" <?php echo $Picture[0]; ?>" height ="200px" width="200px" id="icon" >
- <div id="info">
- <H4> <?php echo $Name[0]; ?></H4> </br>
- </div>
- <div id="prodbuy">
- <h3 id="price"> <?php echo $Price[0] ;?> :- </h3>
- <input type ="text" id="hidden_product" value=" <?php echo $prodId[0] ;?>"/>
- <input type ="hidden" id="hidden_customer" value=" 1"/>
- <input type ="hidden" id="hidden_price" value ="<?php echo $Price[0]; ?>"/>
- <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form();"> Lägg till i varukorg </button>
- </form>
- </div>
- </div>;
- <div id="Prod">
- <form method="post" action="index.php?action=add&id=<?php echo $prodId[1]?>">
- <img src=" <?php echo $Picture[1]; ?>" height ="200px" width="200px" id="icon" >
- <div id="info">
- <H4> <?php echo $Name[1]; ?></H4> </br>
- </div>
- <div id="prodbuy">
- <h3 id="price"> <?php echo $Price[1] ;?> :- </h3>
- <input type ="text" id="hidden_product1" value=" <?php echo $prodId[1] ;?>"/>
- <input type ="hidden" id="hidden_customer1" value=" 1"/>
- <input type ="hidden" id="hidden_price" value ="<?php echo $Price[1]; ?>"/>
- <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form1();"> Lägg till i varukorg </button>
- </form>
- </div>
- </div>;
- <div id="Prod">
- <form method="post" action="index.php?action=add&id=<?php echo $prodId[2]?>">
- <img src=" <?php echo $Picture[2]; ?>" height ="200px" width="200px" id="icon" >
- <div id="info">
- <H4> <?php echo $Name[2]; ?></H4> </br>
- </div>
- <div id="prodbuy">
- <h3 id="price"> <?php echo $Price[2] ;?> :- </h3>
- <input type ="text" id="hidden_product2" value=" <?php echo $prodId[2] ;?>"/>
- <input type ="hidden" id="hidden_customer2" value=" 1"/>
- <input type ="hidden" id="hidden_price" value ="<?php echo $Price[2]; ?>"/>
- <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form2();"> Lägg till i varukorg </button>
- </form>
- </div>
- </div>;
- <div id="Prod">
- <form method="post" action="index.php?action=add&id=<?php echo $prodId[3]?>">
- <img src=" <?php echo $Picture[3]; ?>" height ="200px" width="200px" id="icon" >
- <div id="info">
- <H4> <?php echo $Name[3]; ?></H4> </br>
- </div>
- <div id="prodbuy">
- <h3 id="price"> <?php echo $Price[3] ;?> :- </h3>
- <input type ="text" id="hidden_product3" value=" <?php echo $prodId[3] ;?>"/>
- <input type ="hidden" id="hidden_customer3" value=" 1"/>
- <input type ="hidden" id="hidden_price" value ="<?php echo $Price[3]; ?>"/>
- <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form3();"> Lägg till i varukorg </button>
- </form>
- </div>
- </div>;
- <div id="Prod">
- <form method="post" action="index.php?action=add&id=<?php echo $prodId[4]?>">
- <img src=" <?php echo $Picture[4]; ?>" height ="200px" width="200px" id="icon" >
- <div id="info">
- <H4> <?php echo $Name[4]; ?></H4> </br>
- </div>
- <div id="prodbuy">
- <h3 id="price"> <?php echo $Price[4] ;?> :- </h3>
- <input type ="text" id="hidden_product4" value=" <?php echo $prodId[4] ;?>"/>
- <input type ="hidden" id="hidden_customer4" value=" 1"/>
- <input type ="hidden" id="hidden_price" value ="<?php echo $Price[4]; ?>"/>
- <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form4();"> Lägg till i varukorg </button>
- </form>
- </div>
- </div>;
- <?php
- }
- ?>
- </div>
- <!--</div> -->
- <div id="footer"> <h3>Spelbutik Norra </h3> </div>
- </body>
- </html>
- ----------------------- JAVASCRIPT -------------------------------------------
- function toggleLoginDropDown(){
- document.getElementById("loginDropdown").classList.toggle("show")
- }
- function toggleCartDropDown() {
- document.getElementById("cartDropdown").classList.toggle("show")
- }
- function submit_form(){
- var data1=$('#hidden_customer').val();
- var data2=$('#hidden_product').val();
- var dataTosend='Customer_id='+data1+'&Products_id='+data2;
- $.ajax({
- url: 'func.php',
- data:'Customer_id='+data1+'&Products_id='+data2,
- async: true,
- success: function (data) {
- alert(data)
- },
- }
- );
- }
- function submit_form1(){
- var data1=$('#hidden_customer1').val();
- var data2=$('#hidden_product1').val();
- var dataTosend='Customer_id='+data1+'&Products_id='+data2;
- $.ajax({
- url: 'func.php',
- data:'Customer_id='+data1+'&Products_id='+data2,
- async: true,
- success: function (data) {
- alert(data)
- },
- }
- );
- }
- function submit_form2(){
- var data1=$('#hidden_customer2').val();
- var data2=$('#hidden_product2').val();
- var dataTosend='Customer_id='+data1+'&Products_id='+data2;
- $.ajax({
- url: 'func.php',
- data:'Customer_id='+data1+'&Products_id='+data2,
- async: true,
- success: function (data) {
- alert(data)
- },
- }
- );
- }
- function submit_form3(){
- var data1=$('#hidden_customer3').val();
- var data2=$('#hidden_product3').val();
- var dataTosend='Customer_id='+data1+'&Products_id='+data2;
- $.ajax({
- url: 'func.php',
- data:'Customer_id='+data1+'&Products_id='+data2,
- async: true,
- success: function (data) {
- alert(data)
- },
- }
- );
- }
- function submit_form4(){
- var data1=$('#hidden_customer4').val();
- var data2=$('#hidden_product4').val();
- var dataTosend='Customer_id='+data1+'&Products_id='+data2;
- $.ajax({
- url: 'func.php',
- data:'Customer_id='+data1+'&Products_id='+data2,
- async: true,
- success: function (data) {
- alert(data)
- },
- }
- );
- }
- --------------------------------FUNC.PHP--------------------------------------------
- <?php
- /*$username = $_POST["username"];
- $userpassword = $_POST["userpassword"];
- */
- if(isset($_GET['Customer_id'])){
- $customerID = $_GET["Customer_id"];
- $productsID = $_GET["Products_id"];
- echo "customer id =", $customerID, "prod=", $productsID;
- }
- else{
- echo "Please log in";
- }
- /*
- function addToCart(){
- $link = mysqli_connect('127.0.0.1:3306', '971030', '971030');
- if (!$link) {
- die('Could not connect: ' . mysql_error());
- }
- echo 'Connected successfully';
- mysqli_select_db($link, "db971030");
- echo 'Hello world';
- mysqli_query($link,"INSERT INTO Cart (Customer_id,Products_id)
- VALUES ('1','2')");
- echo 'BYE world';
- }*/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement