Truncated incorrect DOUBLE value. What error is this?

Asked

Viewed 820 times

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 with UPDATE livro SET visitas = visitas+1 WHERE...

  • What kind of data is visitas in the database? Since you are an accountant, you should be INT

  • Is whole.

  • So use visitas = visitas+1 which is simpler.

  • I did, the mistake persists, very strange this mistake guy.

  • Which is the line that makes the mistake?

  • Take a look at the comment I added up there, I printed the book id and it’s "106.Ph", instead of 106.

  • Before the last UPDATE.

  • 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.

Show 4 more comments
No answers

Browser other questions tagged

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