Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "tp1mysql"
  6. ?>
  7.  
  8. <!DOCTYPE html>
  9. <html lang="en">
  10. <head>
  11. <link rel="stylesheet" type="text/css" href="style.css">
  12. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  13. <meta charset="UTF-8">
  14. <title>CRUD</title>
  15. </head>
  16. <body>
  17.  
  18. <section class="createSection">
  19. <h3 class="titreCreate">Create</h3>
  20.  
  21. <form action="#" method="post">
  22. <div class="ligneInsertionTable">
  23. <table>
  24. <tr>
  25. <th>Type</th>
  26. <th>Adresse</th>
  27. <th>Nom</th>
  28. <th>Email</th>
  29. </tr>
  30. <tr>
  31. <td>
  32. <input type="text" class="input" id="type" name="type">
  33. </td>
  34. <td>
  35. <input type="text" class="input" id="adresse" name="adresse">
  36. </td>
  37. <td>
  38. <input type="text" class="input" id="nom" name="nom">
  39. </td>
  40. <td>
  41. <input type="text" class="input" id="email" name="email">
  42. </td>
  43. </tr>
  44. </table>
  45. <input type="submit" value="INSERER" id="bInserer" name="bInserer">
  46. </div>
  47. </form>
  48. </section>
  49.  
  50. <?php
  51.  
  52. /*$conn = new mysqli($servername, $username, $password, $dbname);
  53. if($conn->connect_error){
  54. die("Connection echouée : " . $conn->connect_error);
  55. }
  56. for ($i = 0; $i < 50000; $i++){
  57. $sql = "INSERT INTO users (type, adresse, nom, supprime, email) VALUES (" . rand(0,9) . ", '". rand(0,9) . " rue IUT', 'Nom" . $i . "', '" . rand(0,1) . "', 'email" . $i . "@gmail.com')";
  58. if($conn->query($sql) === TRUE){
  59. echo "Insertion réussie";
  60. }else{
  61. echo "Erreur : " . $sql . " " . $conn->error;
  62. }
  63. }
  64.  
  65. $conn->close();*/
  66.  
  67.  
  68. if(!empty($_POST['type']) && !empty($_POST['adresse']) && !empty($_POST['nom']) && !empty($_POST['email'])){
  69. $conn = new mysqli($servername, $username, $password, $dbname);
  70. if($conn->connect_error){
  71. die("Connection echouée : " . $conn->connect_error);
  72. }
  73. $sql = "INSERT INTO users (type, adresse, nom, supprime, email) VALUES (" . $_POST['type'] . ", '" . $_POST['adresse'] . "', '" . $_POST['nom'] . "', 0, '" . $_POST['email'] . "')";
  74. if($conn->query($sql) === TRUE){
  75. echo "Insertion réussie";
  76. }else{
  77. echo "Erreur : " . $sql . " " . $conn->error;
  78. }
  79. $conn->close();
  80. }
  81. ?>
  82.  
  83. <section class="readSection">
  84.  
  85. <?php
  86.  
  87. ?>
  88.  
  89. <?php
  90.  
  91. $conn = new mysqli($servername, $username, $password, $dbname);
  92. if ($conn->connect_error) {
  93. die("Connection echouée : " . $conn->connect_error);
  94. }
  95. $nbPages = $conn->query("SELECT count(*) as nbLigne from users");
  96. $resultNbPage = $nbPages->fetch_assoc();
  97. echo "Page <form method='post' action='#' id='formTab' name='formTab'><input type='number' value='1' name='choixPage' id='choixPage'> sur " . ceil($resultNbPage['nbLigne']/10) . "<input type='submit' value='OK' id='boutonTab' name='boutonTab'></form> ";
  98.  
  99.  
  100. if(!empty($_POST['choixPage'])){
  101. $page = $_POST['choixPage'];
  102. if (($_POST['choixPage'])<0){
  103. $page = 1;
  104. }
  105. if (($_POST['choixPage'])>ceil($resultNbPage['nbLigne']/10)){
  106. $page = ceil($resultNbPage['nbLigne']/10);
  107. }
  108. $sql = "SELECT * FROM users LIMIT 10 OFFSET " . ($page-1)*10;
  109. $result = $conn->query($sql);
  110.  
  111. if(mysqli_num_rows($result) > 0){
  112. echo "<table id=\"example\" class=\"display\" style=\"width:100%\"><thead><tr><th>ID</th><th>TYPE</th><th>ADRESSE</th><th>NOM</th><th>SUPPRIME</th><th>EMAIL</th><th>ACTION</th></tr></thead><tbody>";
  113. while($row = mysqli_fetch_assoc($result)){
  114. echo "<tr><td class='test'>" . $row['id_users'] . "</td><td>" . $row['type'] . "</td><td>" . $row['adresse'] ."</td><td>" . $row['nom'] . "</td><td>" . $row['supprime'] . "</td><td>" . $row['email'] . "</td><td><img src='modif.png' class='imgModif'><img src='cross.png' class='imgCross'></td></tr>";
  115. }
  116. echo "</tbody></table>";
  117. }
  118. else{
  119. echo "Aucun resultat";
  120. }
  121. }else{
  122. $sql = "SELECT * FROM users LIMIT 10";
  123. $result = $conn->query($sql);
  124.  
  125. if(mysqli_num_rows($result) > 0){
  126. echo "<table id=\"example\" class=\"display\" style=\"width:100%\"><thead><tr><th>ID</th><th>TYPE</th><th>ADRESSE</th><th>NOM</th><th>SUPPRIME</th><th>EMAIL</th><th>ACTION</th></tr></thead><tbody>";
  127. while($row = mysqli_fetch_assoc($result)){
  128. echo "<tr><td class='test'>" . $row['id_users'] . "</td><td>" . $row['type'] . "</td><td>" . $row['adresse'] ."</td><td>" . $row['nom'] . "</td><td>" . $row['supprime'] . "</td><td>" . $row['email'] . "</td><td><img src='modif.png' class='imgModif'><img src='cross.png' class='imgCross'></td></tr>";
  129. }
  130. echo "</tbody></table>";
  131. }
  132. else{
  133. echo "Aucun resultat";
  134. }
  135. }
  136.  
  137. mysqli_close($conn);
  138.  
  139.  
  140. ?>
  141. </section>
  142.  
  143. <script>
  144. </script>
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. </body>
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement