Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. <html>
  2. <style type="text/css">
  3. .tg {border-collapse:collapse;border-spacing:0;}
  4. .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  5. .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  6. .tg .tg-yw4l{vertical-align:top}
  7. </style>
  8. <body>
  9.  
  10. CREATE (doesn't work)
  11. <form name="test" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
  12. artist: <input type="text" name="artist"><br>
  13. title: <input type="text" name="title"><br>
  14. category: <input type="text" name="title"><br>
  15. played: <input type="text" name="title"><br>
  16. tracks: <input type="text" name="title"><br>
  17. reldate: <input type="text" name="title"><br>
  18. <input type="submit">
  19. </form>
  20.  
  21. </body>
  22. </html>
  23.  
  24. <?php
  25. function connect() {
  26. $servername = "localhost";
  27. $username = "root";
  28. $password = "";
  29. $dbname = "labexam";
  30.  
  31. // Create connection
  32.  
  33. $conn = new mysqli($servername, $username, $password, $dbname);
  34.  
  35. // Check connection
  36. if ($conn->connect_error) {
  37. die("Connection failed: " . $conn->connect_error);
  38. }
  39. }
  40.  
  41. if($_POST){
  42. if(isset($_POST['create'])){
  43. create();
  44. }
  45. /*elseif(isset($_GET['read'])){
  46. read();
  47. }*/
  48. }
  49.  
  50. function create() {
  51. // prepare and bind
  52. $conn = connect();
  53.  
  54.  
  55. $stmt = $conn->prepare("INSERT INTO cdset (artist, title, category, played, tracks, reldate) VALUES (?, ?, ?, ?, ?, ?)");
  56. $stmt->bind_param("sssiis", $artist, $title, $category, $played, $tracks, $reldate);
  57. echo $stmt;
  58. $artist = $_POST['artist'];
  59. $title = $_POST['title'];
  60. $category = $_POST['category'];
  61. $played = $_POST['played'];
  62. $tracks = $_POST['tracks'];
  63. $reldate = $_POST['reldate'];
  64.  
  65. $stmt->execute();
  66. return $conn;
  67. }
  68.  
  69.  
  70.  
  71. //$stmt->close();
  72. //$conn->close();
  73. ?>
  74.  
  75. <?php
  76. $servername = "localhost";
  77. $username = "root";
  78. $password = "";
  79. $dbname = "labexam";
  80.  
  81. // Create connection
  82. $conn = new mysqli($servername, $username, $password, $dbname);
  83. // Check connection
  84. if ($conn->connect_error) {
  85. die("Connection failed: " . $conn->connect_error);
  86. }
  87. $sql = "SELECT * FROM cdset";
  88. $result = $conn->query($sql);
  89.  
  90. if ($result->num_rows > 0) {
  91. //echo "test";
  92. // output data of each row
  93. echo "READ
  94. <table class='tg'>
  95. <tr>
  96. <th class='tg-yw4l'>id</th>
  97. <th class='tg-yw4l'>artist</th>
  98. <th class='tg-yw4l'>title</th>
  99. <th class='tg-yw4l'>category</th>
  100. <th class='tg-yw4l'>played</th>
  101. <th class='tg-yw4l'>tracks</th>
  102. <th class='tg-yw4l'>reldate</th>
  103. </tr>";
  104. while($row = $result->fetch_assoc()) {
  105.  
  106. echo "<tr>
  107. <th class='tg-yw4l'>".$row["id"]."</th>
  108. <th class='tg-yw4l'>".$row["artist"]."</th>
  109. <th class='tg-yw4l'>".$row["title"]."</th>
  110. <th class='tg-yw4l'>".$row["category"]."</th>
  111. <th class='tg-yw4l'>".$row["played"]."</th>
  112. <th class='tg-yw4l'>".$row["tracks"]."</th>
  113. <th class='tg-yw4l'>".$row["reldate"]."</th>
  114. </tr>";
  115.  
  116. }
  117. } else {
  118. echo "0 results";
  119. }
  120. echo "</table><br/>
  121. UPDATE<br/><br/>
  122. DELETE";
  123. $conn->close();
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement