Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- </head>
- <style type="text/css">
- body{
- background-image: url("fogo.jpg");
- background-color: red;
- }
- div{
- height: 400px;
- width: 50%;
- background-color:yellow;
- border-radius: 15px;
- margin: auto;
- border: 2px solid white;
- }
- label{
- margin: auto;
- padding: 15px;
- }
- input{
- width: 100%;
- }
- h1{
- text-align: center;
- padding-top:15px;
- }
- .insert{
- width: 100px;
- height: 40px;
- text-align: center;
- margin: auto;
- }
- .listar{
- width: 100px;
- height: 40px;
- text-align: center;
- margin: auto;
- }
- .alterar{
- width: 100px;
- height: 40px;
- text-align: center;
- margin: auto;
- }
- .apagar{
- width: 100px;
- height: 40px;
- text-align: center;
- margin: auto;
- }
- .consultar{
- width: 49%;
- }
- form{
- margin: auto;
- padding: 15px;
- }
- .alert{
- width: 40%;
- height: 100px;
- margin: auto;
- text-align: center;
- padding: 15px;
- background-color: orange;
- color: white;
- }
- td{
- border: 2px solid white;
- border-collapse: collapse;
- }
- .nome{
- width: 49%;
- }
- </style>
- <body>
- <?php
- $turnbd = new mysqli('localhost','root','','exemplo da');
- $tnumero=$tnome=$temail=$ttelefone='';
- if ($turnbd->connect_error) {
- die('Erro na ligação : ('. $turnbd->connect_errno .') '. $turnbd->connect_error);
- }
- //Inserçao
- if(isset($_POST['inserir'])){
- $query = "INSERT INTO alunos(numero,nome,email,telefone) VALUES(?,?,?,?)";
- if ($_POST['numero']=='' || $_POST['nome']=='' || $_POST['email']=='' || $_POST['telefone']=='' ) {
- echo "<div class='alert'><h1>Existem campos que nao foram preenchidos!</h1></div>";
- }
- else{
- $statement = $turnbd->prepare($query);
- $statement->bind_param('issi', $_POST["numero"],
- $_POST["nome"],
- $_POST["email"],
- $_POST["telefone"]);
- $statement->execute();
- if ($statement->affected_rows>0){
- echo "<div class='alert'><h1>Foi inserido/atualizado um registo!</h1></div>";
- }
- else{
- die('Erro: ('. $turnbd->errno .') '. $turnbd->error);
- }
- $tnumero=$tnome=$temail=$ttelefone='';
- $statement->close();
- }
- $turnbd->close();
- }
- //Listagem
- if(isset($_POST['listagem'])){
- $query = "SELECT numero,nome,email,telefone FROM alunos ORDER BY numero";
- $statement = $turnbd->prepare($query);
- $statement->execute();
- $statement->bind_result($tnumero,$tnome,$temail,$ttelefone);
- echo '<table style=" color: white; border: 2px solid white; margin: auto; border-collapse: collapse;">';
- echo "<tr>";
- echo "<td>Numero</td>";
- echo "<td>Nome</td>";
- echo "<td>E-mail</td>";
- echo "<td>Telefone</td>";
- echo "</tr>";
- while ($statement->fetch()) {
- echo "<tr>";
- echo "<td>$tnumero</td>";
- echo "<td>$tnome</td>";
- echo "<td>$temail</td>";
- echo "<td>$ttelefone</td>";
- echo "</tr>";
- }
- echo "</table><br>";
- $tnumero=$tnome=$temail=$ttelefone='';
- $statement->close();
- $turnbd->close();
- }
- //Consulta
- if(isset($_POST['consulta'])){
- $query = "SELECT * FROM alunos WHERE numero=?";
- $statement = $turnbd->prepare($query);
- $statement->bind_param('i',$_POST["numero"]);
- $statement->execute();
- $statement->bind_result($tnumero,$tnome,$temail,$ttelefone);
- if ($statement->fetch()) {
- echo "<div class='alert'><h1>Foi encontrado o registo!!</h1></div>";
- }
- else{
- echo "<div class='alert'><h1>Não foi encontrado o registo!!</h1></div>";
- }
- }
- //Alterar
- if(isset($_POST['alterar'])){
- $query = "SELECT COUNT(*) FROM alunos WHERE numero=?";
- $statement = $turnbd->prepare($query);
- $statement->bind_param('i',$_POST["numero"]);
- $statement->execute();
- $statement->bind_result($nrows);
- $statement->fetch();
- $statement->close();
- if ($nrows>0) {
- $query = "UPDATE alunos SET nome=?,email=?,telefone=? WHERE numero=?";
- $statement = $turnbd->prepare($query);
- $statement->bind_param('ssii', $_POST["nome"],
- $_POST["email"],
- $_POST["telefone"],
- $_POST["numero"]);
- $statement->execute();
- echo "<div class='alert'><h1>Foi feita uma alteraçao!</h1></div>";
- }
- else if ($_POST['numero']=='' || $_POST['nome']=='' || $_POST['email']=='' || $_POST['telefone']=='' ) {
- echo "<div class='alert'><h1>Existem campos que nao foram preenchidos!</h1></div>";
- }
- else{
- echo "<div class='alert'><h1>Não foi encontrado o registo!!</h1></div>";
- }
- }
- //Apagar
- if(isset($_POST['apagar'])){
- $query = "DELETE FROM alunos WHERE numero=?";
- $statement = $turnbd->prepare($query);
- $statement->bind_param('i',$_POST["numero"]);
- if ($statement->execute() && $statement->affected_rows>0) {
- echo "<div class='alert'><h1>Registo eliminado!</h1></div>";
- }
- else{
- echo "<div class='alert'><h1>Não foi encontrado o registo!!</h1></div>";
- }
- }
- /*if(isset($_POST['pesc'])){
- if($_POST['numero']==''){
- echo "<div class='alert'><h1>Existem campos que nao foram preenchidos!</h1></div>";
- }
- else{
- $qr = "select * from alunos where numero=?";
- $ordem = $turnbd->prepare($qr);
- $ordem->bind_param('i', $_POST['numero']);
- $ordem->execute();
- $ordem->bind_result($tnumero, $tnome, $temail, $ttelemovel);
- if($ordem->fetch()){
- echo "<div class='alert'><h1>Foi encontrado o registo!!</h1></div>";
- }
- else{
- echo "<div class='alert'><h1>Nao foi encontrado o registo!!</h1></div>";
- }
- $ordem->close();
- }
- }*/
- /*$statement="select * from alunos order by numero";
- $listart = $turnbd->query($statement);
- while($row1 = $listart->fetch_array()) {
- echo '<option value="'.$row1["numero"].'">'.$row1["nome"].'</option>';
- }
- $statement->free();*/
- ?>
- <div>
- <h1>Gestão de Contactos</h1>
- <form name="form1" action="" method="post">
- <input type="hidden" name="pesc" value="1">
- Pesquisa por nome:<select id="opçoes" name="opcoes" onChange="document.form1.submit();>
- <option value="Selecione um nome">Selecione um nome</option>
- </select>
- </form>
- <form action="" method="post">
- <label>Número:</label><br><input class="nome" type="text" name="numero" value="<?php echo $tnumero; ?>"><input class="consultar" type="submit" name="consulta" value="Consulta"><br>
- <label>Nome:</label><br><input type="text" name="nome" value="<?php echo $tnome; ?>"><br>
- <label>E-mail:</label><br><input type="email" name="email" value="<?php echo $temail; ?>"><br>
- <label>Telefone:</label><br><input type="text" name="telefone" value="<?php echo $ttelefone; ?>"><br><br>
- <input class="insert" type="submit" name="inserir" value="Inserir">
- <input class="listar" type="submit" name="listagem" value="Listar Todos">
- <input class="alterar" type="submit" name="alterar" value="Alterar">
- <input class="apagar" type="submit" name="apagar" value="Apagar">
- </form>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment