Ir para conteúdo
Fórum Script Brasil

vicorrea99

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Sobre vicorrea99

Últimos Visitantes

O bloco dos últimos visitantes está desativado e não está sendo visualizado por outros usuários.

vicorrea99's Achievements

0

Reputação

  1. Olá boa noite! Simplesmente não acontece nada, apenas aparece a mensagem de que o BD foi salvo, mas quando vou verificar nada mudou. O mesmo vale quando vou editar algum dado, apenas quando seleciono a opção de deletar que realmente deleta.
  2. Olá gente, acabei de começar a aprender PHP e HTML e estou tendo que criar um banco de dados que registra uma turma e exibir os dados dessa turma por um site em html, de forma que eu consiga editar os dados da turma pela página e ainda alterar o meu BD, entretanto não consigo adicionar dados e nem editá-los, porém consigo deletar. Segue aqui o código da conexão e da página html: Página html::: <?php include('php_code.php'); ?> <?php if (isset($_GET['edit'])) { $ordem = $_GET['edit']; $update = true; $record = mysqli_query($db, "SELECT * FROM alunos WHERE Ordem='$ordem'"); if (count($record) == 1 ) { $n = mysqli_fetch_array($record); $matricula = $n['Matricula']; $nome = $n['Nome']; $email = $n['E-mail']; } } ?> <!DOCTYPE html> <html> <head> <title>CRUD: CReate, Update, Delete PHP MySQL</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta charset="utf-8"> </head> <body> <?php if (isset($_SESSION['message'])) : ?> <div class="msg"> <?php echo $_SESSION['message']; unset($_SESSION['message']); ?> </div> <?php endif ?> <?php $results = mysqli_query($db, "SELECT * FROM alunos"); ?> <table> <thead><tr> <th>Ordem</th> <th>Matrícula</th> <th>Nome</th> <th>E-mail</th> <th colspan="2">Ação</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_array($results)) { ?> <tr> <td><?php echo $row['Ordem'] ?></td> <td><?php echo $row['Matricula'] ?></td> <td><?php echo $row['Nome'] ?></td> <td><?php echo $row['E-mail'] ?></td> <td> <a href="index.php?edit=<?php echo $row['Ordem']; ?>" class = "edit_btn" >Edit</a> </td> <td> <a href="php_code.php?del=<?php echo $row['Ordem']; ?>" class="del_btn">Delete</a> </td> </tr> <?php } ?> </tbody> </table> <form method="post" action="php_code.php" > <input type="hidden" name="Ordem" value="<?php echo $ordem; ?>"> <input type="text" name="Matricula" value="<?php echo $matricula; ?>"> <input type="text" name="Nome" value="<?php echo $nome; ?>"> <input type="text" name="E-mail" value="<?php echo $email; ?>"> <div class="input-group"> <label>Matrícula</label> <input type="text" name="Matricula" value="<?php echo $matricula; ?>"> </div> <br> <div class="input-group"> <label>Nome</label> <input type="text" name="Nome" value="<?php echo $nome; ?>"> </div> <br> <div class="input-group"> <label>E-mail</label> <input type="text" name="E-mail" value="<?php echo $email; ?>"> </div> <br> <div class="input-group"> <?php if ($update == true): ?> <button class="btn" type="submit" name="update" style="background: #556B2F;" >update</button> <?php else: ?> <button class="btn" type="submit" name="save" >Save</button> <?php endif ?> </div> </form> </body> </html> Código da conexão::: <?php session_start(); $db = mysqli_connect('localhost', 'xxxx', 'xxxxxxxxxxxxxxxxxxxx', 'turma'); // initialize variables $matricula = ""; $nome = ""; $email = ""; $ordem = 0; $update = false; if (isset($_POST['save'])) { $matricula = $_POST['Matricula']; $nome = $_POST['Nome']; $email = $_POST['E-mail']; mysqli_query($db, "INSERT INTO alunos (Matricula, Nome, E-mail) VALUES ('$matricula','$nome','$email')"); $_SESSION['message'] = "Arquivo Salvo"; header('location: index.php'); } if (isset($_POST['update'])) { $matricula = mysqli_real_escape_string($db,$_POST['Matricula']); $nome = mysqli_real_escape_string($db,$_POST['Nome']); $email = mysqli_real_escape_string($db,$_POST['E-mail']); mysqli_query($db, "UPDATE alunos SET Matricula='$matricula', Nome='$nome', E-mail='$email' WHERE Ordem=$ordem"); $_SESSION['message'] = "Address updated!"; header('location: index.php'); } if (isset($_GET['del'])) { $ordem = $_GET['del']; mysqli_query($db, "DELETE FROM alunos WHERE ordem=$ordem"); $_SESSION['message'] = "Address deleted!"; header('location: index.php'); } $results = mysqli_query($db, "SELECT * FROM alunos"); ?>
×
×
  • Criar Novo...