Guest User

Untitled

a guest
Oct 21st, 2019
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  123. ?>
  124.  
  125. <table class="auto-style1">
  126. <col span="1" align="left">
  127.  
  128. <tr>
  129. <td>Broj indexa:</td>
  130. <td>
  131. <input type="text" name="brind" value="<?php echo $index; ?>" size="10" />
  132. </td>
  133. </tr>
  134. <tr>
  135. <td>Prezime:</td>
  136. <td>
  137. <input type="text" name="prezime" value="<?php echo $prezime; ?>" size="12" />
  138. </td>
  139. </tr>
  140. <tr>
  141. <td>Ime:</td>
  142. <td>
  143. <input type="text" name="ime" value="<?php echo $ime; ?>" size="12" />
  144. </td>
  145. </tr>
  146. <tr>
  147. <td>Status:</td>
  148. <td>
  149. <?php if($status==="b") { ?>
  150. <label>B
  151. <input type="radio" name="status" value="b" checked />
  152. </label>
  153.  
  154. <label>S
  155. <input type="radio" name="status" value="s" />
  156. </label>
  157. <?php } else if($status==='s') { ?>
  158. <label>B
  159. <input type="radio" name="status" value="b" />
  160. </label>
  161.  
  162. <label>S
  163. <input type="radio" name="status" value="s" checked/>
  164. </label>
  165. <?php } else { ?>
  166. <label>B
  167. <input type="radio" name="status" value="b" />
  168. </label>
  169.  
  170. <label>S
  171. <input type="radio" name="status" value="s" />
  172. </label>
  173. <?php } ?>
  174. </td>
  175. </tr>
  176. <tr>
  177. <td>Sifra smera:</td>
  178. <td>
  179. <input type="text" name="sifra" value="<?php echo $sifra; ?>" size="10" />
  180. </td>
  181. </tr>
  182.  
  183. <tr>
  184. <td>Slika:</td>
  185. <td>
  186. <input type="file" name="slika" value="" size="10" />
  187. </td>
  188. </tr>
  189.  
  190. <tr>
  191. <td><hr></hr></td>
  192. <td><hr></hr></td>
  193. <td><hr></hr></td>
  194. </tr>
  195.  
  196. <tr>
  197. <td>
  198. <input type="submit" class="button button3" value="DODAJ" name="dodaj" />
  199. </td>
  200. <td>
  201. <input type="submit" class="button button3" value="AZURIRAJ" name="azuriraj" />
  202. </td>
  203. <td>
  204. <input type="submit" class="button button3" value="OBRISI" name="obrisi" />
  205. </td>
  206.  
  207. </tr>
  208. <tr>
  209. <td>
  210. <input type="submit" class="button button5" value="Trazi prezime" name="traziprez" />
  211. </td>
  212. <td>
  213. <input type="submit" class="button button5" value="Trazi index" name="traziind" />
  214. </td>
  215. <td>
  216. <input type="reset" class="button button5" value="Reset" name="reset" />
  217. </td>
  218. </tr>
  219.  
  220. </table>
  221. <fieldset>
  222. <legend>
  223. Opcije pretrage:
  224. </legend>
  225. <select name="polje[]">
  226. <option value="broj_indexa">broj indexa</option>
  227. <option value="ime">ime</option>
  228. <option value="prezime">prezime</option>
  229. <option value="sifra">sifra</option>
  230. </select>
  231. <input type="text" name="polje_p" value="" size="10" />
  232. <input type="submit" class="button button1" value="Pretrazi" name="pretraga" />
  233. </fieldset>
  234. </fieldset>
  235.  
  236. </fieldset>
  237. </form>
  238.  
  239.  
  240.  
  241. </body>
  242. </html>
RAW Paste Data