Advertisement
Guest User

Untitled

a guest
Nov 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. <?php
  2.  
  3. require './Contact.php'; // sprawdzimy pitem czy dobrze to
  4.  
  5. $host = 'localhost';
  6. $user = 'root';
  7. $password = '';
  8. $db = 'ContactList';
  9.  
  10. $mysqli = new mysqli($host,$user,$password,$db);
  11.  
  12. //$edit = ($_GET['edit']);
  13.  
  14. /* dokoncz tu :) */
  15.  
  16. if(isset($_GET['edit'])){
  17. $edit = ($_GET['edit']);
  18. echo $edit;
  19. edicik($mysqli,$edit);
  20. }
  21. elseif(isset($_GET['delete'])){
  22. $delete = ($_GET['delete']);
  23. delejcik($mysqli,$delete);
  24. }else{
  25. insercik($mysqli);
  26. }
  27.  
  28. if ($mysqli->connect_errno) {
  29. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  30. }
  31.  
  32. $stmt = $mysqli->prepare("SELECT id, firstname, lastname, phone, email FROM contact");
  33. $stmt->execute();
  34. $res = $stmt->get_result();
  35. $stmt->close();
  36.  
  37. ?>
  38.  
  39. <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  40. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  41.  
  42. <table>
  43. <tr>
  44. <th>id</th>
  45. <th>fistname</th>
  46. <th>lastname</th>
  47. <th>number</th>
  48. <th>email</th>
  49. <th>edit</th>
  50. <th>remove</th>
  51. </tr>
  52. <?php while($row = $res->fetch_assoc()): ?>
  53. <tr>
  54. <td><?= $row['id'] ?></td>
  55. <td><?= $row['firstname'] ?></td>
  56. <td><?= $row['lastname'] ?></td>
  57. <td><?= $row['phone'] ?></td>
  58. <td><?= $row['email'] ?></td>
  59. <td><a href=index.php?edit=<?= $row['id'] ?> ><i style="color:red" class="fa fa-edit"></i></a></td>
  60. <td><a href=index.php?delete=<?= $row['id'] ?> ><i style="color:blue" class="fa fa-close"></i></a></td>
  61. </tr>
  62. <?php endwhile; ?>
  63. </table>
  64.  
  65. <?php if(isset($_GET['edit'])): ?>
  66. <form action="index.php" method="POST">
  67. <span>You edit record with ID <?php $_GET['edit'] ?> </span>
  68. <span>Imie:</span> <input type="text" name="imieE"></input><br>
  69. <span>Nazwisko:</span> <input type="text" name="nazwE"></input><br>
  70. <span>Telefon:</span> <input type="text" name="telE"></input><br>
  71. <span>Email:</span> <input type="text" name="mailE"></input><br>
  72. <input type="submit" value="zmien mordeczke"></input>
  73. </form>
  74. <?php else: ?>
  75.  
  76. <form action="index.php" method="POST">
  77. <span>Imie:</span> <input type="text" name="imie"></input><br>
  78. <span>Nazwisko:</span> <input type="text" name="nazw"></input><br>
  79. <span>Telefon:</span> <input type="text" name="tel"></input><br>
  80. <span>Email:</span> <input type="text" name="mail"></input><br>
  81. <input type="submit" value="dosmaz mordeczke"></input>
  82. </form>
  83. <?php endif; ?>
  84.  
  85. <?php
  86. function insercik($baza){
  87. $nejm = '';
  88. $sernejm = '';
  89. $fon = '';
  90. $mejl = '';
  91.  
  92. if(isset($_POST['imie'])){
  93. $nejm = $_POST['imie'];
  94. }
  95. if(isset($_POST['nazw'])){
  96. $sernejm = $_POST['nazw'];
  97. }
  98. if(isset($_POST['tel'])){
  99. $fon = $_POST['tel'];
  100. }
  101. if(isset($_POST['mail'])){
  102. $mejl = $_POST['mail'];
  103. }
  104. $stmt = $baza->prepare("INSERT INTO contact(firstname, lastname, phone, email) VALUES ('$nejm', '$sernejm', '$fon', '$mejl');");
  105. $stmt->execute();
  106. $stmt->close();
  107. }
  108.  
  109. function edicik($baza,$ed){
  110. $nejm = '';
  111. $sernejm = '';
  112. $fon = '';
  113. $mejl = '';
  114.  
  115. echo "edit";
  116. echo $ed;
  117.  
  118. if(isset($_POST['imieE'])){
  119. $nejm = $_POST['imieE'];
  120. }
  121. if(isset($_POST['nazwE'])){
  122. $sernejm = $_POST['nazwE'];
  123. }
  124. if(isset($_POST['telE'])){
  125. $fon = $_POST['telE'];
  126. }
  127. if(isset($_POST['mailE'])){
  128. $mejl = $_POST['mailE'];
  129. }
  130.  
  131. echo $nejm;
  132. echo $sernejm;
  133. echo $fon;
  134. echo $mejl;
  135.  
  136. $stmt = $baza->prepare("UPDATE contact SET firstname='$nejm', lastname='$sernejm', phone='$fon', email='$mejl' WHERE id='$ed';");
  137. $stmt->execute();
  138. $stmt->close();
  139. }
  140.  
  141. function delejcik($baza,$del){
  142. $stmt = $baza->prepare("DELETE FROM contact WHERE id='$del';");
  143. $stmt->execute();
  144. $stmt->close();
  145. }
  146. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement