Why aren’t you pulling the id GET variable?

Asked

Viewed 248 times

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>
  • that form he wouldn’t have to be giving a Submit to somewhere?

  • When you hover the mouse on the link comes to show the filled id?

  • $_GET and not $GET

  • When the mouse passes the right filled id but it seems not to be pulling id and variable $given gets undefined

  • Even changing $GET to $_GET doesn’t change anything

1 answer

1

the problem is that Voce is writing:

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

when it’s actually

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

Because that?

good if you declare $qualquercoisa is like a normal php variable, but $_ these are the statements for proper php variables for example $_POST or $_GET among others.

Browser other questions tagged

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