Why is not pulling the variable GET id? [closed]

0

index.php

    <table border="0" width="100%">
        <a href="insere.php">Adicionar</a>
        <tr>
            <th>Nome:</th>
            <th>E-mail:</th>
            <th>Açoes:</th>     
        </tr>
    <?php
        $sql = "SELECT * FROM usuarios";
        $sql = $pdo->query($sql);
            if ($sql->rowCount()>0) {

            foreach ($sql->fetchALL() as $usuario) {
                echo '<tr>';
                echo '<td>'.$usuario['nome'].'</td>';
                echo '<td>'.$usuario['email'].'</td>';
                echo '<td><a href="editar.php?id='.$usuario['id'].'">Editar</a> - 
                <a href="excluir.php?id='.$usuario['id'].'">Excluir</a></td>';

                echo'</tr>';
            }

            }else{echo "Sem Conexao";}
    ?>
    </table>

edit.php

<?php
require'conecta.php';
$id = 0;
if (isset($GET['id']) && !empty($GET['id'])){
    $id = addslashes($GET['id']);

    $sql = "SELECT * FROM usuarios WHERE id = '$id'";
    $sql = $pdo->query($sql);
        if ($sql->rowCount()<0) {
            $dado = $sql->fetch();

        }
    }


?>

<form method="POST">
    Nome:</br>
    <input type="text" name="nome" value="<?php echo $dado['nome']; ?>"></br>
    E-mail:</br>
    <input type="text" name="email" value="<?php echo $dado['email']; ?>"></br>
    Senha</br>
    <input type="password" name="senha"></br>
    <input type="submit" value="Atualizar">
</form>
    
asked by anonymous 05.02.2018 / 14:09

1 answer

1

The problem is that you are writing:

if (isset($GET['id']) && !empty($GET['id'])){

When in fact it is

if (isset($_GET['id']) && !empty($_GET['id'])){

Why this?

Good if you declare $qualquercoisa is like a normal php variable, but $ _ these are the declarations for php's own variables eg $_POST or $_GET among others.

    
05.02.2018 / 14:13