Advertisement
Guest User

Untitled

a guest
Nov 26th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.26 KB | None | 0 0
  1. <!doctype html>
  2. <?php //All kod ligger i denna pastebin
  3. include("func.php");
  4. session_start();
  5. $link = mysqli_connect('127.0.0.1:3306', '970414', '970414');
  6. if (!$link) {
  7. die('Could not connect: ' . mysql_error());
  8. }
  9.  
  10. mysqli_select_db($link, "db970414");
  11. /*
  12. if(isset ($_POST["add_to_cart"])){
  13. echo "Add to cart is set";
  14. if(isset ($_SESSION["shopping_cart"])){
  15. $idProd = $_POST["hidden_id"];
  16. if(isset($_POST["add_to_cart"])){
  17. addToCart($link, $idProd);
  18.  
  19.  
  20. $count = count($_SESSION["shopping_cart"]);
  21. $Products_array = array(
  22. 'idProducts' => $_POST["hidden_id"],
  23. 'Products_name' => $_POST["hidden_name"],
  24. 'Products_Price' => $_POST["hidden_price"]
  25. );
  26. $_SESSION["shopping_cart"][$count] = $Products_array; // Lägger till vara i varukorgen
  27.  
  28.  
  29. }
  30. else{
  31. $Products_array = array(
  32. 'idProducts' => $_POST["hidden_id"],
  33. 'Products_name' => $_POST["hidden_name"],
  34. 'Products_Price' => $_POST["hidden_price"]
  35. );
  36. $_SESSION["shopping_cart"][0] = $Products_array;// Lägger till första varan i varukorgen
  37. }
  38.  
  39. }
  40.  
  41. }*/
  42. ?>
  43.  
  44. <html>
  45. <script src="script.js"></script>
  46. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"> </script>
  47. <link rel="stylesheet" href="style.css">
  48. <head> <title>Spelbutik Norra</title> </head>
  49. <body>
  50.  
  51. <H1 class="head">Spelbutik Norra</H1> <br>
  52. <div class="dropdown">
  53. <button class="dropbutton" onclick="toggleLoginDropDown()">
  54. Logga in
  55. </button>
  56. <div class="dropdown-content" id="loginDropdown" >
  57. <form action="func.php" method="post">
  58. Användarnamn: <input type="text" name="username"><br>
  59. Lösenord:<br> <input type="password" name="userpassword"><br>
  60. <input type="submit" value="Logga in">
  61. </form>
  62. </div>
  63. <button class="dropbuttonVaru" onclick="toggleCartDropDown()">Varukorg</button>
  64. <div class="dropdown-content-varu" id="cartDropdown" >
  65.  
  66. </div>
  67. </div>
  68.  
  69.  
  70. <!-- <div class="grid-container">-->
  71. <div id="base">
  72. <?php
  73. $prodResult = mysqli_query($link, "SELECT * FROM Products");
  74.  
  75. if (mysqli_num_rows($prodResult) > 0) {
  76. $count = 0;
  77. $prodId[] = array();
  78. $Price[] = array();
  79. $Name[] = array();
  80. $picture[] = array();
  81. while($row = mysqli_fetch_assoc($prodResult)) {
  82. /*echo "id: " . $row["idProducts"];*/
  83. $Price[$count] = $row["Price"];
  84. $Name[$count] = $row["Name"];
  85. $Picture[$count] = $row["Picture"];
  86. $prodId[$count] = $row["idProducts"];
  87. $count = $count + 1;
  88. }
  89. ?>
  90.  
  91. <div id="Prod">
  92. <form method="post" action="index.php?action=add&id=<?php echo $prodId[0]?>">
  93. <img src=" <?php echo $Picture[0]; ?>" height ="200px" width="200px" id="icon" >
  94. <div id="info">
  95. <H4> <?php echo $Name[0]; ?></H4> </br>
  96. </div>
  97. <div id="prodbuy">
  98. <h3 id="price"> <?php echo $Price[0] ;?> :- </h3>
  99. <input type ="text" id="hidden_product" value=" <?php echo $prodId[0] ;?>"/>
  100. <input type ="hidden" id="hidden_customer" value=" 1"/>
  101. <input type ="hidden" id="hidden_price" value ="<?php echo $Price[0]; ?>"/>
  102. <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form();"> Lägg till i varukorg </button>
  103. </form>
  104. </div>
  105. </div>;
  106. <div id="Prod">
  107. <form method="post" action="index.php?action=add&id=<?php echo $prodId[1]?>">
  108. <img src=" <?php echo $Picture[1]; ?>" height ="200px" width="200px" id="icon" >
  109. <div id="info">
  110. <H4> <?php echo $Name[1]; ?></H4> </br>
  111. </div>
  112. <div id="prodbuy">
  113. <h3 id="price"> <?php echo $Price[1] ;?> :- </h3>
  114. <input type ="text" id="hidden_product1" value=" <?php echo $prodId[1] ;?>"/>
  115. <input type ="hidden" id="hidden_customer1" value=" 1"/>
  116. <input type ="hidden" id="hidden_price" value ="<?php echo $Price[1]; ?>"/>
  117. <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form1();"> Lägg till i varukorg </button>
  118. </form>
  119. </div>
  120. </div>;
  121. <div id="Prod">
  122. <form method="post" action="index.php?action=add&id=<?php echo $prodId[2]?>">
  123. <img src=" <?php echo $Picture[2]; ?>" height ="200px" width="200px" id="icon" >
  124. <div id="info">
  125. <H4> <?php echo $Name[2]; ?></H4> </br>
  126. </div>
  127. <div id="prodbuy">
  128. <h3 id="price"> <?php echo $Price[2] ;?> :- </h3>
  129. <input type ="text" id="hidden_product2" value=" <?php echo $prodId[2] ;?>"/>
  130. <input type ="hidden" id="hidden_customer2" value=" 1"/>
  131. <input type ="hidden" id="hidden_price" value ="<?php echo $Price[2]; ?>"/>
  132. <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form2();"> Lägg till i varukorg </button>
  133. </form>
  134. </div>
  135. </div>;
  136. <div id="Prod">
  137. <form method="post" action="index.php?action=add&id=<?php echo $prodId[3]?>">
  138. <img src=" <?php echo $Picture[3]; ?>" height ="200px" width="200px" id="icon" >
  139. <div id="info">
  140. <H4> <?php echo $Name[3]; ?></H4> </br>
  141. </div>
  142. <div id="prodbuy">
  143. <h3 id="price"> <?php echo $Price[3] ;?> :- </h3>
  144. <input type ="text" id="hidden_product3" value=" <?php echo $prodId[3] ;?>"/>
  145. <input type ="hidden" id="hidden_customer3" value=" 1"/>
  146. <input type ="hidden" id="hidden_price" value ="<?php echo $Price[3]; ?>"/>
  147. <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form3();"> Lägg till i varukorg </button>
  148. </form>
  149. </div>
  150. </div>;
  151. <div id="Prod">
  152. <form method="post" action="index.php?action=add&id=<?php echo $prodId[4]?>">
  153. <img src=" <?php echo $Picture[4]; ?>" height ="200px" width="200px" id="icon" >
  154. <div id="info">
  155. <H4> <?php echo $Name[4]; ?></H4> </br>
  156. </div>
  157. <div id="prodbuy">
  158. <h3 id="price"> <?php echo $Price[4] ;?> :- </h3>
  159. <input type ="text" id="hidden_product4" value=" <?php echo $prodId[4] ;?>"/>
  160. <input type ="hidden" id="hidden_customer4" value=" 1"/>
  161. <input type ="hidden" id="hidden_price" value ="<?php echo $Price[4]; ?>"/>
  162. <button type ="button" name="add_to_cart" id="Buy" onclick="submit_form4();"> Lägg till i varukorg </button>
  163. </form>
  164. </div>
  165. </div>;
  166. <?php
  167.  
  168. }
  169.  
  170.  
  171. ?>
  172. </div>
  173.  
  174. <!--</div> -->
  175. <div id="footer"> <h3>Spelbutik Norra </h3> </div>
  176. </body>
  177. </html>
  178.  
  179.  
  180.  
  181.  
  182. ----------------------- JAVASCRIPT -------------------------------------------
  183.  
  184.  
  185.  
  186. function toggleLoginDropDown(){
  187. document.getElementById("loginDropdown").classList.toggle("show")
  188. }
  189.  
  190. function toggleCartDropDown() {
  191. document.getElementById("cartDropdown").classList.toggle("show")
  192. }
  193.  
  194. function submit_form(){
  195.  
  196. var data1=$('#hidden_customer').val();
  197. var data2=$('#hidden_product').val();
  198. var dataTosend='Customer_id='+data1+'&Products_id='+data2;
  199.  
  200. $.ajax({
  201. url: 'func.php',
  202. data:'Customer_id='+data1+'&Products_id='+data2,
  203. async: true,
  204. success: function (data) {
  205. alert(data)
  206. },
  207. }
  208.  
  209. );
  210. }
  211. function submit_form1(){
  212.  
  213. var data1=$('#hidden_customer1').val();
  214. var data2=$('#hidden_product1').val();
  215. var dataTosend='Customer_id='+data1+'&Products_id='+data2;
  216.  
  217. $.ajax({
  218. url: 'func.php',
  219. data:'Customer_id='+data1+'&Products_id='+data2,
  220. async: true,
  221. success: function (data) {
  222. alert(data)
  223. },
  224. }
  225.  
  226. );
  227. }
  228. function submit_form2(){
  229.  
  230. var data1=$('#hidden_customer2').val();
  231. var data2=$('#hidden_product2').val();
  232. var dataTosend='Customer_id='+data1+'&Products_id='+data2;
  233.  
  234. $.ajax({
  235. url: 'func.php',
  236. data:'Customer_id='+data1+'&Products_id='+data2,
  237. async: true,
  238. success: function (data) {
  239. alert(data)
  240. },
  241. }
  242.  
  243. );
  244. }
  245. function submit_form3(){
  246.  
  247. var data1=$('#hidden_customer3').val();
  248. var data2=$('#hidden_product3').val();
  249. var dataTosend='Customer_id='+data1+'&Products_id='+data2;
  250.  
  251. $.ajax({
  252. url: 'func.php',
  253. data:'Customer_id='+data1+'&Products_id='+data2,
  254. async: true,
  255. success: function (data) {
  256. alert(data)
  257. },
  258. }
  259.  
  260. );
  261. }
  262. function submit_form4(){
  263.  
  264. var data1=$('#hidden_customer4').val();
  265. var data2=$('#hidden_product4').val();
  266. var dataTosend='Customer_id='+data1+'&Products_id='+data2;
  267.  
  268. $.ajax({
  269. url: 'func.php',
  270. data:'Customer_id='+data1+'&Products_id='+data2,
  271. async: true,
  272. success: function (data) {
  273. alert(data)
  274. },
  275. }
  276.  
  277. );
  278. }
  279.  
  280.  
  281. --------------------------------FUNC.PHP--------------------------------------------
  282.  
  283.  
  284. <?php
  285.  
  286. /*$username = $_POST["username"];
  287. $userpassword = $_POST["userpassword"];
  288. */
  289. if(isset($_GET['Customer_id'])){
  290. $customerID = $_GET["Customer_id"];
  291. $productsID = $_GET["Products_id"];
  292.  
  293. echo "customer id =", $customerID, "prod=", $productsID;
  294. }
  295. else{
  296. echo "Please log in";
  297. }
  298. /*
  299. function addToCart(){
  300. $link = mysqli_connect('127.0.0.1:3306', '971030', '971030');
  301. if (!$link) {
  302. die('Could not connect: ' . mysql_error());
  303. }
  304. echo 'Connected successfully';
  305. mysqli_select_db($link, "db971030");
  306.  
  307. echo 'Hello world';
  308. mysqli_query($link,"INSERT INTO Cart (Customer_id,Products_id)
  309. VALUES ('1','2')");
  310. echo 'BYE world';
  311. }*/
  312. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement