Advertisement
jpvieiraa

PHP VIEIRA

Feb 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Exemplo</title>
  5. <style type="text/css">
  6. #ger1{
  7. margin: auto;
  8. background-color: #993333;
  9. color: white;
  10. width: 500px;
  11. height: auto;
  12. border:2px solid black;
  13. border-radius: 10px;
  14. }
  15. .ger2{
  16. margin: auto;
  17. background-color: #993333;
  18. color: white;
  19. width: 500px;
  20. height: auto;
  21. border:2px solid black;
  22. border-radius: 10px;
  23. }
  24. p{
  25. text-align: center;
  26. }
  27.  
  28. .alerta{
  29. border-radius: 10px;
  30. text-align: center;
  31. margin: auto;
  32. background-color: red;
  33. margin-right: 20px;
  34. margin-left: 20px;
  35. }
  36. .done{
  37. border-radius: 10px;
  38. text-align: center;
  39. margin: auto;
  40. background-color: green;
  41. margin-right: 20px;
  42. margin-left: 20px;
  43. }
  44. .tabelanova{
  45. margin: auto;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <?php
  51. $bd_host="localhost";
  52. $bd_user="root";
  53. $bd_password="";
  54. $bd_database="13787_3";
  55. $msg= "";
  56. $existe="";
  57. $numero=$idade=$email=$local="";
  58. $mq = new mysqli($bd_host,$bd_user,$bd_password,$bd_database);
  59.  
  60.  
  61.  
  62. if(isset($_POST["submit"])){
  63. $qr = "INSERT INTO tbl_13787(Numero,Idade,Email,Local) VALUES(?,?,?,?)";
  64. $st = $mq->prepare($qr);
  65. $st->bind_param('iiss', $_POST["Numero"],
  66. $_POST["Nome"],
  67. $_POST["Email"],
  68. $_POST["Local"]);
  69.  
  70. if ($st->execute() && $st->affected_rows>0){
  71. $msg= "<p class='done'>Foi inserido/atualizado um registo!</p>";
  72.  
  73. }
  74. else{
  75. $msg='<p class="alerta"> Erro: ('. $mq->errno .') '. $mq->error .'</p>';
  76. $erro=1;
  77. }
  78.  
  79. $st->close();
  80.  
  81.  
  82.  
  83. }
  84. if(isset($_POST["Consultar"])){
  85. $qr="SELECT * FROM tbl_13787 ORDER BY Numero";
  86.  
  87. $results = $mq->query($qr);
  88. echo "<table class=tabelanova border='1'>";
  89. echo "<td>Numero</td>";
  90. echo "<td>Idade</td>";
  91. echo "<td>Email</td>";
  92. echo "<td>Local</td>";
  93. while ($row = $results->fetch_assoc()) {
  94. echo "<tr>";
  95. echo "<td>".$row["Numero"]."</td>";
  96. echo "<td>".$row["Idade"]."</td>";
  97. echo "<td>".$row["Email"]."</td>";
  98. echo "<td>".$row["Local"]."</td>";
  99. echo "</tr>";
  100. }
  101. echo "</table>";
  102. }
  103. else{
  104.  
  105. if(isset($_POST["pesquisar"])){
  106.  
  107. $qr="SELECT * FROM tbl_13787 where Numero=?";
  108. $st=$mq->prepare($qr);
  109. $st->bind_param('i', $_POST["Numero"]);
  110. $st->execute();
  111. $st->bind_result($numero,$idade,$email,$local);
  112. if($st->fetch()){
  113. $existe=true;
  114. $msg='<p class="done" > Registo Encontrado</p>';
  115.  
  116. }
  117. else{
  118. $existe=false;
  119. $msg='<p class="alerta">Registo nao Encontrado</p>';
  120. }
  121. $st->close();
  122. }
  123. else{
  124. if(isset($_POST["Alterar"])){
  125. $qr="UPDATE tbl_13787 SET Idade=?, Email=?, Local=? WHERE Numero=?";
  126. $st=$mq->prepare($qr);
  127. $st->bind_param('issi',$_POST["Idade"],$_POST["Email"],$_POST["Local"],$_POST["Numero"]);
  128. $st->execute();
  129. $st->close();
  130. }
  131. else{
  132. if(isset($_POST["Apagar"])){
  133. $qr="DELETE FROM tbl_13787 WHERE Numero= ?";
  134. $st=$mq->prepare($qr);
  135. $st->bind_param('i',$_POST["Numero"]);
  136. $st->execute();
  137. $st->close();
  138. }
  139. }
  140. }
  141. }
  142.  
  143.  
  144. ?>
  145. <br>
  146. <form method="post" action="" id="tbl" class=ger2 name="tbl">
  147. <input type="hidden" name="pesquisar" value="1"/>
  148. <p>Seleciona: <select name="Numero" id="Numero" onChange="document.tbl.submit();">
  149. <option value="-1">
  150. Selecione um registo
  151. </option>
  152. <?php
  153. $qrs="SELECT * FROM tbl_13787";
  154. $st = $mq->query($qrs);
  155. $option = '';
  156. while($row = $st->fetch_assoc())
  157. {
  158. echo '<option value = "'.$row['Numero'].'">'.$row['Numero'].'</option>';
  159. }
  160. $st->close();
  161. ?>
  162. </select>
  163. </form>
  164. <form method="post" action="" id="ger1" class="ger2">
  165. <p>Numero:<input type="number" name="Numero" value="<?php echo $numero ?>"><input type="submit" name="pesquisar" value="Pesquisar registo"></p>
  166. <p>Idade:<input type="number" name="Idade" value="<?php echo $idade ?>"></p>
  167. <p>Email:<input type="text" name="Email" value="<?php echo $email ?>"></p>
  168. <p>Local:<input type="text" name="Local" value="<?php echo $local ?>"></p>
  169. <p><input type="submit" name="submit" value="Inserir registo" id="botao1"></p>
  170. <p><input type="submit" name="Consultar" value="Consultar registo" id="botao2"></p>
  171. <?php if ($existe==true) {?>
  172. <p><input type="submit" name="Alterar" value="Alterar registo" /></p>
  173. <p><input type="submit" name="Apagar" value="Eliminar registo" /></p>
  174. <?php }?>
  175. <p>
  176. <?php
  177. echo $msg;
  178. $mq->close();
  179. ?>
  180. </p>
  181. </form>
  182. </body>
  183. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement