Advertisement
Guest User

alou

a guest
Oct 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title>CRUD APLIKACIJA</title>
  11. </head>
  12. <body style="background-color: #f0e68c">
  13. <h2>Unos, azuriranje i brisanje podataka o studentima</h2>
  14. <form action="index.php" method="POST" enctype="multipart/form-data">
  15. <fieldset>
  16. <legend>Podaci o studentima:</legend>
  17.  
  18.  
  19. <?php
  20. // uvoz konekcije
  21. require_once './konekcija.php';
  22.  
  23. $index=$ime=$prezime=$status=$sifra="";
  24.  
  25. // provera tastera
  26. if (isset($_POST['dodaj'])) {
  27. if (!$_POST['brind'] || !$_POST['ime'] ||
  28. !$_POST['prezime'] || !$_POST['status'] ||
  29. !$_POST['sifra'] || empty($_FILES['slika'])) {
  30.  
  31. echo 'Svi podaci moraju biti uneti!';
  32. } else {
  33.  
  34. // UPLOAD SLIKE NA SERVER
  35. if (!empty($_FILES['slika'])) {
  36. // echo '<pre>';
  37. // var_dump($_FILES['slika']);
  38. // echo "</pre>";
  39.  
  40. // da li je uneti fajl slika ili nijei to formata jpeg
  41. if($_FILES['slika']['type'] == 'image/jpeg'){
  42. // provera da li postoji direktorijum koji se zove slike
  43. if(is_dir('slike')){
  44. $source = $_FILES['slika']['tmp_name']; // temp fajl treba prebaciti na odredjenu lokaciju
  45. $putanja = "slike/".$_FILES['slika']['name'];
  46. move_uploaded_file($source, $putanja);
  47.  
  48. }else{
  49. // ukoliko ne postoji direktorijum kreiraj ga
  50. mkdir('slike');
  51. }
  52. }
  53. // KRAJ UPLOAD SLIKE NA SERVER
  54.  
  55.  
  56.  
  57. // UPISIVANJE PODATAKA U BAZU
  58. //priprema upita za bazu
  59. $stmt = $conn->prepare("INSERT INTO `STUDENT`"
  60. . "(`broj_indexa`, `ime`, `prezime`, `status`,"
  61. . "`sifra`, `slika`) "
  62. . "values (?,?,?,?,?,?)");
  63.  
  64. // povezivanje podataka sa tipovima promenljivih
  65. $stmt->bind_param("ssssss", $index, $ime, $prezime, $status, $sifra, $slika);
  66. $index = $_POST['brind'];
  67. $ime = $_POST['ime'];
  68. $prezime = $_POST['prezime'];
  69. $status = $_POST['status'];
  70. $sifra = $_POST['sifra'];
  71. $slika = $_FILES['slika']['name'];
  72.  
  73. // provera i izvrsavanje upita
  74. if(!$stmt->execute()){
  75. echo 'Greska: '.$conn->errno."- ".$conn->error;
  76. } else {
  77. echo 'Podaci uspesno uneti u bazu';
  78. }
  79.  
  80. // oslobadjanje resursa
  81. $stmt->close();
  82. $conn->close();
  83.  
  84. // KRAJ UPISIVANJA PODATAKA U BAZU
  85.  
  86. } else {
  87. echo 'Greska!';
  88. }
  89. }
  90. }
  91.  
  92. /*************************PRETRAGA PO INDEXU***********************/
  93. if(isset($_POST['traziind'])){
  94. if(!empty($_POST['brind'])){
  95.  
  96. $stmt = $conn->prepare("SELECT * FROM `student` WHERE `broj_indexa`=?");
  97. $stmt->bind_param("s",$indexForma);
  98.  
  99. $indexForma = $_POST['brind'];
  100.  
  101. if(!$stmt->execute()){
  102. echo "Greska ".$conn->errno." - ".$conn->error;
  103. }
  104. else{
  105. // uzimanje pojedinacnog podatka kao asocijativni niz
  106. $podatak = $stmt->get_result();
  107. $red = $podatak->fetch_assoc();
  108. $index = $red['broj_indexa'];
  109. $ime = $red['ime'];
  110. $prezime = $red['prezime'];
  111. $status = $red['status'];
  112. $sifra = $red['sifra'];
  113. }
  114. echo $status;
  115.  
  116. }else{
  117. echo "Parametar po kome se vrsi pretraga nije upisan!";
  118. }
  119.  
  120. }
  121.  
  122. if(isset($_POST['azuriraj'])){
  123.  
  124. $stmt = $conn->prepare("UPDATE `student` SET *"
  125. . "`ime' = ?, "
  126. . "`prezime` = ?, "
  127. . "`status` = ?, "
  128. . "`sifra = ?,"
  129. . "WHERE `student`.`broj_indexa` =?");
  130.  
  131. $stmt->bind_param("sssss",$ime,$prezime,$status,$sifra,$index);
  132.  
  133. $index = $_POST['brind'];
  134. $ime = $_POST['ime'];
  135. $prezime = $_POST['prezime'];
  136. $status = $_POST['status'];
  137. $sifra = $_POST['sifra'];
  138. if(!stmt->execute()){
  139. echo 'Greska:'.$stmt->errno." - ".$stmt->error;
  140.  
  141. } else {
  142. echo 'Podaci su uspesno update-ovani';
  143. }
  144. }
  145.  
  146. ?>
  147.  
  148. <table class="auto-style1">
  149. <col span="1" align="left">
  150.  
  151. <tr>
  152. <td>Broj indexa:</td>
  153. <td>
  154. <input type="text" name="brind" value="<?php echo $index; ?>" size="10" />
  155. </td>
  156. </tr>
  157. <tr>
  158. <td>Prezime:</td>
  159. <td>
  160. <input type="text" name="prezime" value="<?php echo $prezime; ?>" size="12" />
  161. </td>
  162. </tr>
  163. <tr>
  164. <td>Ime:</td>
  165. <td>
  166. <input type="text" name="ime" value="<?php echo $ime; ?>" size="12" />
  167. </td>
  168. </tr>
  169. <tr>
  170. <td>Status:</td>
  171. <td>
  172. <?php if($status==="b") { ?>
  173. <label>B
  174. <input type="radio" name="status" value="b" checked />
  175. </label>
  176.  
  177. <label>S
  178. <input type="radio" name="status" value="s" />
  179. </label>
  180. <?php } else if($status==='s') { ?>
  181. <label>B
  182. <input type="radio" name="status" value="b" />
  183. </label>
  184.  
  185. <label>S
  186. <input type="radio" name="status" value="s" checked/>
  187. </label>
  188. <?php } else { ?>
  189. <label>B
  190. <input type="radio" name="status" value="b" />
  191. </label>
  192.  
  193. <label>S
  194. <input type="radio" name="status" value="s" />
  195. </label>
  196. <?php } ?>
  197. </td>
  198. </tr>
  199. <tr>
  200. <td>Sifra smera:</td>
  201. <td>
  202. <input type="text" name="sifra" value="<?php echo $sifra; ?>" size="10" />
  203. </td>
  204. </tr>
  205.  
  206. <tr>
  207. <td>Slika:</td>
  208. <td>
  209. <input type="file" name="slika" value="" size="10" />
  210. </td>
  211. </tr>
  212.  
  213. <tr>
  214. <td><hr></hr></td>
  215. <td><hr></hr></td>
  216. <td><hr></hr></td>
  217. </tr>
  218.  
  219. <tr>
  220. <td>
  221. <input type="submit" class="button button3" value="DODAJ" name="dodaj" />
  222. </td>
  223. <td>
  224. <input type="submit" class="button button3" value="AZURIRAJ" name="azuriraj" />
  225. </td>
  226. <td>
  227. <input type="submit" class="button button3" value="OBRISI" name="obrisi" />
  228. </td>
  229.  
  230. </tr>
  231. <tr>
  232. <td>
  233. <input type="submit" class="button button5" value="Trazi prezime" name="traziprez" />
  234. </td>
  235. <td>
  236. <input type="submit" class="button button5" value="Trazi index" name="traziind" />
  237. </td>
  238. <td>
  239. <input type="reset" class="button button5" value="Reset" name="reset" />
  240. </td>
  241. </tr>
  242.  
  243. </table>
  244. <fieldset>
  245. <legend>
  246. Opcije pretrage:
  247. </legend>
  248. <select name="polje[]">
  249. <option value="broj_indexa">broj indexa</option>
  250. <option value="ime">ime</option>
  251. <option value="prezime">prezime</option>
  252. <option value="sifra">sifra</option>
  253. </select>
  254. <input type="text" name="polje_p" value="" size="10" />
  255. <input type="submit" class="button button1" value="Pretrazi" name="pretraga" />
  256. </fieldset>
  257. </fieldset>
  258.  
  259. </fieldset>
  260. </form>
  261.  
  262.  
  263.  
  264. </body>
  265. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement