Redirect click to the page with the id that I want?

0

Page where the posts are:

<!DOCTYPE html>

                   

<header>
    <a href="index.php">
        <p id="nome">contos</p>
    </a>
</header>
<div id="leitura">
    <?php  

    include_once('db.php');

    $sql = "SELECT * FROM conto";
    $resultado = mysqli_query($db,$sql);

    if($resultado === FALSE) {
        // Consulta falhou, parar aqui 
    die(mysqli_error());
    }

    while ($row = mysqli_fetch_array($resultado)) {
        $id = $row['id'];
        $nome = $row['nome'];
        $genero = $row['genero'];
        $titulo = $row['titulo'];
        $conto = $row['conto'];
    ?>
    <a href="leitura.php?id='$id'">
    <div class="post">
        <h1 class="titulo"><?php echo $titulo; ?></h1>
        <hr class="linha">
        <div class="info">
            <div class="autor">
                <span><i class="fa fa-user" aria-hidden="true"></i> Autor: <?php echo $nome; ?></span>
            </div>
            <div class="genero">
                <span><i class="fa fa-transgender" aria-hidden="true"></i> Gênero: <?php echo $genero; ?></span>
            </div>
        </div>
    </div>
    </a>
    <hr class="linha">
    <?php } ?>

</div>

This is the reading page:

<?php  

include_once('db.php');

$sql = "SELECT * FROM conto WHERE id ='".$_GET['id']."'";
$resultado = mysqli_query($db,$sql);
$row = mysqli_fetch_array($resultado);
    $id = $row['id'];
    $nome = $row['nome'];
    $genero = $row['genero'];
    $titulo = $row['titulo'];
    $conto = $row['conto'];

if($row['id'] == ''){
    echo "está vazio";
    exit;
}

? >                    

<header>
    <a href="index.php">
        <p id="nome">contos</p>
    </a>
</header>

    <?php 
         echo '<p>'.$row['conto'].'</p>';  
     ?>

Connection code:

<?php  

$db = mysqli_connect("localhost","root","","contos");

? >

    
asked by anonymous 26.09.2016 / 00:21

1 answer

0

Try to check for connection errors in leitura.php :

if($resultado === FALSE) {
// Consulta falhou, parar aqui 
die(mysqli_error());
}

Now do the following, comment here the link code you are trying to create for each home page post! That one from WHILE!

Logically, this link would take the page leitura.php?id= and the id corresponding to the post! After entering leitura.php , it shows the complete post according to the id in the GET! Method

Now the error can be in the link you are trying to create in Home WHILE! So the GET id is empty, try to make a manual request! That is, in the browser enter the url with any id! And see if it works.

  • UPDATE :

Try to put a echo (' before each line in the while-home HTML! And a '); in the end! I've always done it, and never made mistakes!

    
26.09.2016 / 00:51