2
On this page I select the book id to display it and then update the visits field, incrementing it.
<?php
if(isset($_GET['id']))
{
$id = $_GET['id'];
}
$livros = mysqli_query($conexao, "SELECT nome, descricao, imagem, download,
visitas FROM livro WHERE id='$id'")or die(mysqli_error($conexao));
if(mysqli_num_rows($livros) <= 0)
{
echo "<h2>Banco de dados não retornou nenhum valor</h2>";
}
while($res_livros = mysqli_fetch_array($livros))
{
$nome = $res_livros['0'];
$descricao = $res_livros['1'];
$imagem = $res_livros['2'];
$download = $res_livros['3'];
$visitas = $res_livros['4'];
}
?>
<h1><?=$nome;?></h1>
<a data-fancybox="gallery" href="uploads/livros/<?=$imagem;?>">
<figure>
<img class="alignright" width="200" src="uploads/livros/<?=$imagem;?>"/>
<figcaption><a id="download" href="<?=$download?>">Download</a>
</figcaption>
</figure>
</a>
<h3><?=$descricao?></h3>
</section>
</div>
<?php
if(isset($visitas))
{
$add_visitas = $visitas + 1;
$up_visitas = mysqli_query($conexao, "UPDATE livro SET visitas =
'$add_visitas' WHERE id='$id'")or die(mysqli_error($conexao));
}
?>
I am posting the whole code but the error happens is here, in the book UPDATE.
Guys, now I decided to have the id printed down here and appeared the book id +". php", like this: 106.php. That’s why it’s giving Boolean, but where is this ". php" coming from? In the database is only the normal number.
I solved the problem here, it was my bullshit, obviously I passed the . php together with the page id but for some reason SELECT had no conflict with this, but UPDATE did.
Remove the simple quotes from
'$add_visitas'
and test. But you could increase withUPDATE livro SET visitas = visitas+1 WHERE...
– Sam
What kind of data is
visitas
in the database? Since you are an accountant, you should beINT
– Sam
Is whole.
– user122195
So use
visitas = visitas+1
which is simpler.– Sam
I did, the mistake persists, very strange this mistake guy.
– user122195
Which is the line that makes the mistake?
– Sam
Take a look at the comment I added up there, I printed the book id and it’s "106.Ph", instead of 106.
– user122195
Before the last UPDATE.
– user122195
I can kind of do a gambit and pull this . php out of the string, but now I want to know how it got there.
– user122195