Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Exemplo</title>
- <style type="text/css">
- #ger1{
- margin: auto;
- background-color: #993333;
- color: white;
- width: 500px;
- height: auto;
- border:2px solid black;
- border-radius: 10px;
- }
- .ger2{
- margin: auto;
- background-color: #993333;
- color: white;
- width: 500px;
- height: auto;
- border:2px solid black;
- border-radius: 10px;
- }
- p{
- text-align: center;
- }
- .alerta{
- border-radius: 10px;
- text-align: center;
- margin: auto;
- background-color: red;
- margin-right: 20px;
- margin-left: 20px;
- }
- .done{
- border-radius: 10px;
- text-align: center;
- margin: auto;
- background-color: green;
- margin-right: 20px;
- margin-left: 20px;
- }
- .tabelanova{
- margin: auto;
- }
- </style>
- </head>
- <body>
- <?php
- $bd_host="localhost";
- $bd_user="root";
- $bd_password="";
- $bd_database="13787_3";
- $msg= "";
- $existe="";
- $numero=$idade=$email=$local="";
- $mq = new mysqli($bd_host,$bd_user,$bd_password,$bd_database);
- if(isset($_POST["submit"])){
- //if($_POST["Idade"]!='' && ...)
- $qr = "INSERT INTO tbl_13787(Numero,Idade,Email,Local) VALUES(?,?,?,?)";
- $st = $mq->prepare($qr);
- $st->bind_param('iiss', $_POST["Numero"],
- $_POST["Idade"],
- $_POST["Email"],
- $_POST["Local"]);
- if ($st->execute() && $st->affected_rows>0){
- $msg= "<p class='done'>Foi inserido/atualizado um registo!</p>";
- }
- else{
- $msg='<p class="alerta"> Erro: ('. $mq->errno .') '. $mq->error .'</p>';
- $erro=1;
- }
- $st->close();
- }
- if(isset($_POST["Consultar"])){
- $qr="SELECT * FROM tbl_13787 ORDER BY Numero";
- $results = $mq->query($qr);
- echo "<table class=tabelanova border='1'>";
- echo "<td>Numero</td>";
- echo "<td>Idade</td>";
- echo "<td>Email</td>";
- echo "<td>Local</td>";
- while ($row = $results->fetch_assoc()) {
- echo "<tr>";
- echo "<td>".$row["Numero"]."</td>";
- echo "<td>".$row["Idade"]."</td>";
- echo "<td>".$row["Email"]."</td>";
- echo "<td>".$row["Local"]."</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- else{
- if(isset($_POST["pesquisar"])){
- $qr="SELECT * FROM tbl_13787 where Numero=?";
- $st=$mq->prepare($qr);
- $st->bind_param('i', $_POST["Numero"]);
- $st->execute();
- $st->bind_result($numero,$idade,$email,$local);
- if($st->fetch()){
- $existe=true;
- $msg='<p class="done" > Registo Encontrado</p>';
- }
- else{
- $existe=false;
- $msg='<p class="alerta">Registo nao Encontrado</p>';
- }
- $st->close();
- }
- else{
- if(isset($_POST["Alterar"])){
- $qr="UPDATE tbl_13787 SET Idade=?, Email=?, Local=? WHERE Numero=?";
- $st=$mq->prepare($qr);
- $st->bind_param('issi',$_POST["Idade"],$_POST["Email"],$_POST["Local"],$_POST["Numero"]);
- $st->execute();
- $st->close();
- }
- else{
- if(isset($_POST["Apagar"])){
- $qr="DELETE FROM tbl_13787 WHERE Numero= ?";
- $st=$mq->prepare($qr);
- $st->bind_param('i',$_POST["Numero"]);
- $st->execute();
- $st->close();
- }
- }
- }
- }
- ?>
- <br>
- <form method="post" action="" id="tbl" class=ger2 name="tbl">
- <input type="hidden" name="pesquisar" value="1"/>
- <p>Seleciona: <select name="Numero" id="Numero" onChange="document.tbl.submit();">
- <option value="-1">
- Selecione um registo
- </option>
- <?php
- $qrs="SELECT * FROM tbl_13787";
- $st = $mq->query($qrs);
- $option = '';
- while($row = $st->fetch_assoc())
- {
- echo '<option value = "'.$row['Numero'].'">'.$row['Numero'].'</option>';
- }
- $st->close();
- ?>
- </select>
- </form>
- <form method="post" action="" id="ger1" class="ger2">
- <p>Numero:<input type="number" name="Numero" value="<?php echo $numero ?>"><input type="submit" name="pesquisar" value="Pesquisar registo"></p>
- <p>Idade:<input type="number" name="Idade" value="<?php echo $idade ?>"></p>
- <p>Email:<input type="text" name="Email" value="<?php echo $email ?>"></p>
- <p>Local:<input type="text" name="Local" value="<?php echo $local ?>"></p>
- <p><input type="submit" name="submit" value="Inserir registo" id="botao1"></p>
- <p><input type="submit" name="Consultar" value="Consultar registo" id="botao2"></p>
- <?php if ($existe==true) {?>
- <p><input type="submit" name="Alterar" value="Alterar registo" /></p>
- <p><input type="submit" name="Apagar" value="Eliminar registo" /></p>
- <?php }?>
- <p>
- <?php
- echo $msg;
- $mq->close();
- ?>
- </p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement