Advertisement
EduzZiTo

Untitled

May 13th, 2019
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Galeria</title>
  5. <meta charset="utf-8">
  6.  
  7. <style type="text/css">
  8. button {
  9.  
  10. background-color: rgb(236, 240, 241);
  11. border: none;
  12. color: black;
  13.  
  14. text-align: center;
  15. text-decoration: none;
  16. display: inline;
  17.  
  18. }
  19. a:link {
  20. color: black;
  21. text-decoration: none;
  22. }
  23.  
  24. a:visited {
  25. color: black;
  26. text-decoration: none;
  27. }
  28.  
  29. a:hover {
  30. color: black;
  31. text-decoration: none;
  32. }
  33.  
  34. a:active {
  35. color: black;
  36. text-decoration: none;
  37. }
  38. .nav{
  39. background-color: rgb(63, 195, 128);
  40. border-radius: 7px;
  41. text-align: center;
  42. padding-bottom: 1px;
  43. padding-top: 3px;
  44. }
  45. body{
  46. background-color: rgb(46, 49, 49);
  47. color: white;
  48. font-family: "Comic Sans Ms"
  49. }
  50. fieldset{
  51. margin-left: auto;
  52. margin-right: auto;
  53. width: 550px;
  54. height: 300px;
  55. }
  56. .form{
  57. padding-top: 20px;
  58. text-align: center;
  59. font-size: 30px;
  60. }
  61. .form2{
  62. padding-top: 20px;
  63. text-align: center;
  64. font-size: 30px;
  65.  
  66. }
  67. .erro{
  68. background-color: rgb(192, 57, 43);
  69. width: 300px;
  70. margin-left: auto;
  71. margin-right: auto;
  72. }
  73. .erro,.sucesso,.ok{
  74. text-align: center;
  75. }
  76. .sucesso,.ok{
  77. background-color: rgb(30, 130, 76);
  78. width: 300px;
  79. margin-left: auto;
  80. margin-right: auto;
  81. }
  82.  
  83. </style>
  84. </head>
  85. <body>
  86. <?php
  87. $bd_host="localhost";
  88. $bd_user="root";
  89. $bd_password="";
  90. $bd_database="galeria";
  91.  
  92. $mysqli = new mysqli($bd_host,$bd_user,$bd_password,$bd_database);
  93.  
  94. // Mostrar erros, caso existam
  95. if ($mysqli->connect_error) {
  96. die('Erro: ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
  97. }
  98.  
  99. $msg="";
  100. $leq1=$leq2=$llocal=$ldata=$lg1=$lg2='';
  101. ?>
  102. <div class="nav">
  103. <h1>Galeria</h1>
  104. <nav><button>Gerenciar Galeria</button><button><a href="galeria2.php" target="_self">Ver Galeria</a></button></nav>
  105. </div>
  106.  
  107.  
  108. <div class="form">
  109. <form method="POST" action="">
  110. <label>Tipo:</label>&nbsp;&nbsp;<input type="text" name="tipo">&nbsp;&nbsp;<input type="submit" name="submitx" value="Novo"><br>
  111. <?php
  112. if (isset($_POST["submitx"])){
  113. if($_POST['tipo']==''){
  114. $msg='<h3 class="erro">Erro, Existem campos por preencher!</h3>';
  115.  
  116. }
  117. else{
  118. $query = "INSERT INTO galeria(tipo) VALUES (?)";
  119. $statement = $mysqli->prepare($query);
  120. $statement->bind_param('s', $_POST["tipo"]);
  121. if ($statement->execute() && $statement->affected_rows>0){
  122. $msg= "<div class='ok'>Foi inserido/atualizado um registo!</div>";}
  123.  
  124. $statement->close();
  125. }
  126. }
  127. ?>
  128. </form>
  129. </div>
  130. <div class="form2">
  131. <form method="post" enctype="multipart/form-data">
  132. <fieldset>
  133. <legend>Informações:</legend>
  134.  
  135. Imagem: <input type="file" name="imagem" value=""><br>
  136. Titulo:&nbsp;&nbsp; <input style="width: 296px;"type="text" name="titulo"><br>
  137. Descrição:&nbsp;&nbsp; <input style="width: 238px;" type="text" name="descricao"><br>
  138. Tipo:&nbsp;&nbsp; <select name="123" style="width: 321px; height: 25px;"><br>
  139. <?php
  140. $qr="SELECT tipo FROM galeria";
  141. $st = $mysqli->query($qr);
  142. while($row = $st->fetch_assoc())
  143. {
  144. echo '<option value = "'.$row['tipo'].'">'.$row['tipo'].' </option>';
  145. }
  146. $st->close();
  147. ?>
  148. </select><br>
  149. Data:&nbsp;&nbsp; <input style="width: 312px;" type="date" name="data"><br>
  150. <input type="submit" name="submitz" value="Inserir"><br>
  151. </fieldset>
  152. </form>
  153. </div>
  154.  
  155. <?php
  156. if(isset($_POST['submitz']))
  157. {
  158. if($_POST['titulo']=='' || $_POST['descricao']=='' || $_POST['data']==''){
  159. $msg='<h3 class="erro">Erro, Existem campos por preencher!</h3>';
  160. }
  161. else{
  162. $destino = "fotos/a" . $_POST['titulo'] . ".jpg" ;
  163.  
  164. if($_FILES["imagem"]["type"]=="image/jpeg"){
  165. if(move_uploaded_file($_FILES['imagem']['tmp_name'], $destino)) {
  166.  
  167. // echo '<img src="' . $destino. '">';
  168.  
  169.  
  170.  
  171.  
  172. $qr = "INSERT INTO galeria_fotos (imagem,titulo,descricao,data,tipo) VALUES(?,?,?,?,?)";
  173.  
  174.  
  175.  
  176. $st = $mysqli->prepare($qr);
  177.  
  178. $st->bind_param('sssss',$destino, $_POST["titulo"], $_POST["descricao"], $_POST["data"],$_POST["123"]);
  179.  
  180.  
  181. if ($st->execute() && $st->affected_rows>0){
  182. $msg='<h3 class="sucesso">A fotografia foi inserida!</h3>';
  183. }
  184. else{
  185. $msg='<h3 class="erro" >Erro: ('. $mysqli->errno .') '. $mysqli->error . '</h3>';
  186. $erro=1;
  187. }
  188. $st->close();
  189. }
  190. }
  191. }
  192. }
  193. ?>
  194. <?php
  195. echo "<br>";
  196. echo $msg;
  197.  
  198. ?>
  199.  
  200. </body>
  201. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement