Guest User

Untitled

a guest
Sep 30th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  6. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  7.  
  8. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  9.  
  10. <script
  11. src="https://code.jquery.com/jquery-3.3.1.min.js"
  12. integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  13. crossorigin="anonymous"></script>
  14.  
  15. <title>Ajax Tests</title>
  16. </head>
  17. <body>
  18. <div class="container-fluid">
  19. <!-- Afficher suivi billets -->
  20. <h2>Billets avec suivi activé</h2>
  21. <table class="table table-striped">
  22. <thead>
  23. <tr>
  24. <th>Billet</th>
  25. <th>Technicien</th>
  26. <th>Date suivi</th>
  27. <th>Heure suivi</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <?php
  32. $servername = "localhost";
  33. $username = "root";
  34. $password = "";
  35. $dbname = "suiviBillets";
  36.  
  37. // Create connection
  38. $conn = mysqli_connect($servername, $username, $password, $dbname);
  39. // Check connection
  40. if (!$conn) {
  41. die("Erreur de connexion: " . mysqli_connect_error());
  42. }
  43.  
  44. $sql = "SELECT billet, technicien, date, heure FROM suiviBillets";
  45. $result = mysqli_query($conn, $sql);
  46.  
  47. if (mysqli_num_rows($result) > 0) {
  48. // output data of each row
  49. while($row = mysqli_fetch_assoc($result)) {
  50. echo "<tr><td>" . $row["billet"]. "</td><td>"
  51. . $row["technicien"]. "</td><td>"
  52. . $row["date"]. "</td><td>"
  53. . $row["heure"]. "</td></tr>";
  54. }
  55. } else {
  56. echo "Aucun r&eacute;sultat";
  57. }
  58.  
  59. mysqli_close($conn);
  60. ?>
  61. <tbody>
  62. </table>
  63. <!-- Afficher Billets -->
  64. <h2>Tous les billets</h2>
  65. <table class="table table-striped">
  66. <thead>
  67. <tr>
  68. <th>Billet</th>
  69. <th>Client</th>
  70. <th>Technicien</th>
  71. <th>Date suivi</th>
  72. <th>Heure suivi</th>
  73. <th>Suivre</th>
  74. </tr>
  75. </thead>
  76. <tbody>
  77. <?php
  78. $servername = "localhost";
  79. $username = "root";
  80. $password = "";
  81. $dbname = "suiviBillets";
  82.  
  83. // Create connection
  84. $conn = mysqli_connect($servername, $username, $password, $dbname);
  85. // Check connection
  86. if (!$conn) {
  87. die("Erreur de connexion: " . mysqli_connect_error());
  88. }
  89.  
  90. $sql = "SELECT billet, nomClient, technicien FROM billets";
  91. $result = mysqli_query($conn, $sql);
  92.  
  93. if (mysqli_num_rows($result) > 0) {
  94. // output data of each row
  95. while($row = mysqli_fetch_assoc($result)) {
  96. echo "<tr><td><input type="hidden" name="billet".$row["billet"]."" id="billet".$row["billet"]."" value="".$row["billet"]."">" . $row["billet"]. "</td><td>"
  97. . $row["nomClient"]. "</td><td><input type="hidden" value="".$row["technicien"]."">"
  98. . $row["technicien"].
  99. "</td><td><input type="text" name="date".$row["billet"]."" id="date".$row["billet"].""></td>
  100. <td><input type="text" name="heure".$row["billet"]."" id="heure".$row["billet"].""></td>
  101. <td><button type="button" class="btn btn-success btn-block" name="insert-data".$row["billet"]."" id="insert-data".$row["billet"]."">Suivre</button></td><p class="message"></p></tr>";
  102. }
  103. } else {
  104. echo "Aucun r&eacute;sultat";
  105. }
  106.  
  107. mysqli_close($conn);
  108. ?>
  109. <tbody>
  110. </table>
  111. </div>
  112. <!-- Script pour envoi donnée via ajax -->
  113. <script type="text/javascript">
  114.  
  115. $(document).ready(function(){
  116. $("#insert-data<?php echo $row["billet"]; ?>").click(function(){
  117. var billet=$("#billet<?php echo $row["billet"]; ?>").val();
  118. var technicien=$("technicien<?php echo $row["billet"]; ?>").val();
  119. var date=$("#date<?php echo $row["billet"]; ?>").val();
  120. var heure=$("#heure<?php echo $row["billet"]; ?>").val();
  121.  
  122.  
  123. // AJAX code to send data to php file.
  124. $.ajax({
  125. method: "POST",
  126. url: "insert-data.php",
  127. data: {billet:billet,technicien:technicien,date:date,heure:heure},
  128. dataType: "JSON",
  129. success: function(data) {
  130. $(".message").html(data);
  131. $("p").addClass("alert alert-success");
  132. },
  133. error: function(err) {
  134. alert(err);
  135. }
  136. });
  137.  
  138. });
  139. });
  140.  
  141. </script>
  142. </body>
  143. </html>
  144.  
  145. <?php
  146.  
  147. $conn = new mysqli('localhost', 'root', '', 'suiviBillets');
  148. $billet=$_POST['billet'];
  149. $technicien=$_POST['technicien'];
  150. $date=$_POST['date'];
  151. $heure=$_POST['heure'];
  152.  
  153. $sql="INSERT INTO 'suiviBillets' ('billet', 'technicien', 'date', 'heure') VALUES ('$billet', '$technicien', '$date', '$heure')";
  154. if ($conn->query($sql) === TRUE) {
  155. echo "data inserted";
  156. }
  157. else
  158. {
  159. echo "failed";
  160. }
  161.  
  162. ?>
Add Comment
Please, Sign In to add comment