Advertisement
tmen

auctionHome.php

Oct 22nd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <!doctype html>
  2. <?php
  3. session_start();
  4. if(isset($_SESSION['status'])) {
  5. echo "session running";
  6. echo "<br>currently logged in: " . $_SESSION["name"] . ".<br>";
  7. }
  8. else
  9. {
  10. session_destroy();
  11. header("Location: auctionLoginForm.html");
  12. }
  13. ?>
  14. <html>
  15. <head>
  16. <meta charset="utf-8">
  17. <title>Auction Home</title>
  18. </head>
  19.  
  20. <body>
  21. <h1>Available items for purchase*:</h1>
  22. <h6>*Bidding and buying capabilities to be added later</h6>
  23. <h3><a href="auctionPostForm.html">Post an item up for auction</a>
  24. <?php
  25. function logout() {
  26. session_destroy();
  27. //echo "refreshing";
  28. header("Location: auctionLoginForm.html");
  29. }
  30. if (isset($_GET['hello'])) {
  31. logout();
  32. //setcookie("user", "", time() - 3600);
  33. }
  34. echo "<table style='border: solid 1px black;'>";
  35. echo "<tr><th>id</th><th>item</th><th>description</th><th>start bid price</th><th>post time</th><th>poster</th><th>expiration date</th><th>current bid price</th></tr>";
  36.  
  37. class TableRows extends RecursiveIteratorIterator {
  38. function __construct($it) {
  39. parent::__construct($it, self::LEAVES_ONLY);
  40. }
  41.  
  42. function current() {
  43. return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
  44. }
  45.  
  46. function beginChildren() {
  47. echo "<tr>";
  48. }
  49.  
  50. function endChildren() {
  51. echo "</tr>" . "\n";
  52. }
  53. }
  54.  
  55. $servername = "localhost";
  56. $username = "playground18";
  57. $password = "Cdz5SOVrY2p8fnWS";
  58. $dbname = "playground18";
  59.  
  60. try
  61. {
  62. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  63. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  64. $stmt = $conn->prepare("SELECT * FROM tanay_auction_items");
  65. $stmt->execute();
  66.  
  67. // set the resulting array to associative
  68. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  69. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v)
  70. {
  71. echo $v;
  72. }
  73. }
  74. catch(PDOException $e)
  75. {
  76. echo "Error: " . $e->getMessage();
  77. }
  78. $conn = null;
  79. echo "</table>";
  80. ?>
  81. <a href='auctionHome.php?hello=true'>Logout</a>
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement