Help with CRUD code

Asked

Viewed 52 times

0

I am creating a CRUD on 000webhost using phpmyadmin

I’m not being able to include a new user on the site. If I create a new user by the database it appears on the site, but if created by the site returns that saved the new user but is not saved in the database or on the site itself. How do I include a new user in the database by the site?

The code of save php. that’s the one:

<?php
include_once "../servico/Autenticacao.php";
include_once "../servico/Bd.php";

$login=$_GET["login"];
$senha=$_GET["senha"];

if 
    (isset($_GET['id'])) { //atualiza
    $id = $_GET['id'];
    $sql = "update `usuario` set login='$login', senha='$senha' where id='$id' ";
    
        
    }else { //grava um novo
    $sql = "INSERT INTO `usuario` (`login`, `senha`) VALUES ('$login', '$senha')";    
    
    
}

$bd = new Bd();
$contador = $bd->exec($sql);

echo "<h1>foi armazenado/atualizado</h1>";

?>

<a href="ConsultarUsuario.php">Voltar</a>

The code of Include.php that I’m using is this:


<?php
include_once "../servico/Autenticacao.php";
?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css">
    <title>Gerenciamento de usuários</title>
  </head>
  <body>
      
    <div class="container">
        
        <h1>Tela de inclusão de usuários</h1>
         <hr>
        <a href="ConsultarUsuario.php"> < Voltar </a>
        
       <br><br>
        
        <form action="salvar.php">
          <div class="form-group">
            <label for="exampleInputEmail1">Login</label>
            <input type="text" name="login" class="form-control"  >
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1">Senha</label>
            <input type="password" name="senha" class="form-control" >
          </div>
          <button type="submit" class="btn btn-primary">Salvar</button>
        </form>

       
        <br><br>
   </div> <!-- container -->
    
    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script> 

    <!-- Option 2: jQuery, Popper.js, and Bootstrap JS
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script> -->
    
     
  </body>
</html>

  • One remark: The field $_GET['id'] does not appear in your html form, probably you wanted to take this session information $_SESSION['id']. Another note: it is not advisable to send information such as password using get, it would be more appropriate to use post.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.