Problem with PHP in the edit form

Asked

Viewed 67 times

-1

Guys, I need some help. I’m doing a PHP job, but I can’t edit it through the form or log in.
edita-usuario.php /

<?php
    session_start();
    include "conexao.php";
    $id = $_GET['idusuario'];
    $sql = "SELECT * FROM usuario WHERE id={$id}";
    $usuario = $conn->query($sql);
    //print_r($cliente->fetch_assoc());  
    $dados = $usuario->fetch_assoc();
    //echo $dados['email'];
     $conn->close();
?>
    <?php include "include/header.php" ?>

  <h1>Edita Cliente</h1>
    <form method="get" action="atualizar-usuario.php" >

    <input type="hidden" name="id" size="15" 
            value="<?php echo $dados['id'];?>" /> 

        <label>E-mail</label>
        <input type="text" name="email" size="15" 
            value="<?php echo $dados['email'];?>" /> 
        <br/>

        <label>Senha</label>
        <input type="text" name="senha" size="15"  
            value="<?php echo $dados['senha'];?>" />
        <br/>
        <input type="submit" value="Atualizar" />
    </form>
    <?php include "include/footer.php" ?>

update-user.php

<?php include "conexao.php"; $id = $_POST['id']; $EmailUsuario = $_POST['email']; $SenhaUsuario = $_POST['senha']; $sql = "UPDATE usuario SET email='{$EmailUsuario}', senha='{$SenhaUsuario}' WHERE id={$id}"; if ($conn->query($sql) === TRUE) { echo "Atualizado com sucesso"; }else { echo "Error: " . $conn->error; } $conn->close(); ?>
  • update-user.php <? php include "connection.php"; $id = $_POST['id']; $Emailusuario = $_POST['email']; $Senhausuario = $_POST['password']; $sql = "UPDATE usuario SET email='{$Emailusuario}', password='{$Senhausuario}' WHERE id={$id}"; if ($Conn->query($sql) === TRUE) { echo "Updated successfully"; }Else { echo "Error: " . $Conn->error; } $Conn->close(); ?>

  • Put this in your question and not in the comments.

1 answer

0


How did you put the content of atualizar-usuario.php in the comments got a little bad to understand...

What I realized is that you are sending the data by GET:

<form method="get" action="atualizar-usuario.php" >

But at update-user.php you are expecting data via POST.

Adjust the form to send data via POST or adjust the PHP code to receive data via GET.

Solution 1:

<form method="POST" action="atualizar-usuario.php" >

Solution 2

<?php 
include "conexao.php"; 
$id = $_GET['id']; 
$EmailUsuario = $_GET['email']; 
$SenhaUsuario = $_GET['senha']; 
$sql = "UPDATE usuario SET email='{$EmailUsuario}', senha='{$SenhaUsuario}' WHERE id={$id}";
if ($conn->query($sql) === TRUE) {
    echo "Atualizado com sucesso"; 
}else { 
    echo "Error: " . $conn->error; 
} 
$conn->close(); 

?> 

Some links fold HTTP METHODS: - HTTP METHODS: https://www.w3schools.com/tags/ref_httpmethods.asp

  • Thanks, it worked!

Browser other questions tagged

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