Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <?php
  2. $host = 'localhost';
  3. $user = 'root';
  4. $pass = 'firma2016';
  5. $db = 'pailab4';
  6. $conn = mysql_connect($host, $user, $pass);
  7. if (!$conn)
  8. die('Error: ' . mysql_error());
  9.  
  10. $db = mysql_select_db($db, $conn);
  11.  
  12. if (!$db)
  13. die('Error: ' . mysql_error());
  14.  
  15. session_start();
  16.  
  17.  
  18.  
  19. if($_POST)
  20. {
  21. if($_POST["ocena"])
  22. {
  23. $ocena = htmlspecialchars(trim($_POST['ocena']));
  24. }
  25.  
  26. if($_POST["przedmiot"])
  27. {
  28. $przedmiot = htmlspecialchars(trim($_POST['przedmiot']));
  29. }
  30.  
  31. if($_POST["add"])
  32. {
  33. if(!empty($ocena) && !empty($przedmiot))
  34. {
  35. mysql_query("INSERT INTO PAI4 SET ocena = '" .$ocena. "', przedmiot='" .$przedmiot. "'");
  36. }
  37. header("Przedmiot?: ?");
  38. }
  39.  
  40. if($_POST["modify"])
  41. {
  42. $idEditRow = htmlspecialchars(trim($_POST["idEditRow"]));
  43. if(!empty($ocena) && !empty($przedmiot))
  44. {
  45. mysql_query("UPDATE PAI4 SET ocena = '" .$ocena. "', przedmiot='" .$przedmiot. "' WHERE id = '" .$idEditRow. "'");
  46. }
  47. header("Przedmiot?: ?");
  48. }
  49.  
  50. if($_POST["delete"])
  51. {
  52. $deleteRow = $_POST["delete"];
  53. foreach($deleteRow as $idDeleteRow)
  54. {
  55. mysql_query("DELETE FROM PAI4 WHERE id = '" .$idDeleteRow. "'");
  56. header('Przedmiot?: ?');
  57. }
  58. $result = mysql_result(mysql_query("SELECT COUNT(*) FROM PAI4"));
  59. if($result == 0)
  60. {
  61. mysql_query("ALTER TABLE PAI4 AUTO_INCREMENT = 1");
  62. }
  63. }
  64. }
  65. ?>
  66.  
  67. <?php
  68. $orderASC = "asc";
  69. $orderDESC = "desc";
  70. $cookieName = "sortTableColumn";
  71. if(!$_GET)
  72. {
  73. $query = "SELECT * FROM PAI4";
  74. $cookieValue = "asc";
  75. setcookie($cookieName,$cookieValue);
  76. }
  77. else
  78. {
  79. $orderSort = $_GET["order"];
  80. $sort = $_GET['sort'];
  81. $cookieValue = $_COOKIE[$cookieName];
  82. if($orderSort == $cookieValue)
  83. {
  84. $query = "SELECT * FROM PAI4 ORDER BY " .$sort. " " .$orderDESC;
  85. $cookieValue = $orderDESC;
  86. setcookie($cookieName,$cookieValue);
  87. }
  88. else
  89. {
  90. $query = "SELECT * FROM PAI4 ORDER BY " .$sort. " " .$orderASC;
  91. $cookieValue = $orderASC;
  92. setcookie($cookieName,$cookieValue);
  93. }
  94. }
  95. $resultQuery = mysql_query($query);
  96.  
  97. echo
  98. '<form action="?" method="post">
  99. <input type="hidden" name="delete" value="delete">
  100. <center>
  101. <table border="1" style="border-collapse: collapse;font-family: Arial; font-size:14px;">
  102. <tr>
  103. <th> <a href="?sort=id&order=asc">ID</a> </th>
  104. <th> <a href="?sort=ocena&order=asc">OCENA</a> </th>
  105. <th> <a href="?sort=przedmiot&order=asc">PRZEDMIOT</a> </th>
  106. <th> <input type="submit" name="edit" value="EDYTUJ"> </th>
  107. <th> <input type="submit" name="delete" value="USUŃ"> </th>
  108. </tr>';
  109.  
  110. while($row=mysql_fetch_row($resultQuery))
  111. {
  112. echo '<tr>
  113. <td>' .$row[0]. '</td>
  114. <td>' .$row[1]. '</td>
  115. <td>' .$row[2]. '</td>
  116. <td> <input type="radio" name="idEditRow" value=' .$row[0]. '></td>
  117. <td> <input type="checkbox" name="delete[]" value=' .$row[0]. '> </td>
  118. </tr>';
  119. }
  120. echo "</table></form><hr>";
  121.  
  122. $result = mysql_result(mysql_query("SELECT MAX(id) as id FROM PAI4"),0) + 1;
  123. echo
  124. '<p style="font-family: Arial; font-size: 14px;"><strong>Dodawanie:</strong></p>
  125. <form action="?" method="post">
  126. <input style="max-width: 30px;" type="text" name="id" placeholder = "' .$result. '" readonly>
  127. <input type="text" name="ocena" placeholder="Ocena">
  128. <input type="text" name="przedmiot" placeholder="Przedmiot">
  129. <input type="submit" name="add" value="Dodaj">
  130. </form></center>';
  131.  
  132. if($_POST["edit"])
  133. {
  134. $idEditRow = $_POST["idEditRow"];
  135. if($idEditRow >= 1)
  136. {
  137. echo
  138. '<center><hr>
  139. <p style="font-family: Arial; font-size: 14px;"><strong>Modyfikacja:</strong></p>
  140. <form action="z2.php" method="post">
  141. <input style="max-width: 30px;" type="text" name="id" placeholder = "' .$idEditRow. '" readonly>
  142. <input type="text" name="ocena" placeholder="Ocena">
  143. <input type="text" name="przedmiot" placeholder="Przedmiot">
  144. <input type="hidden" name="idEditRow" value="' .$idEditRow. '">
  145. <input type="submit" name="modify" value="Edytuj"><hr style="margin-top: 16px;"></center>';
  146. }
  147. }
  148. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement