Implement a fun button in PHP and mysqli

0

I'm trying to implement a liking button on a system that I'm designing as test. It already changes the value of tanned in the database, however I have to put the value in an input field that I put. So every number that I put in the input and click on enjoy it does the update in my database. I would like to know how I do not need to enter the value in the input and every time I click it it adds another number to the value it already has in the database. Here is the code:

Index.php

<?php 

  require_once "conecta.php";

  $resultado = mysqli_query($conexao, "select * from curtida");
  $curtida = mysqli_fetch_assoc($resultado);
?>

<!DOCTYPE html>
<html lang="pt-br">
<head>
  <meta charset="UTF-8" />
  <title>Curtir</title>
  <link rel="stylesheet" href="css/claudina.css" />
</head>
<body>
  <section class="recipiente margem-topo-50">
   <form action="envia_curtir.php" method="post">
   <input type="number" name="curtida" />
   <button class="icones icone-polegares-para-cima"></button>
   <?=$curtida['curtidas'];?>
    </form>
  </section>
</body>
</html>  


send_curtir.php

<?php

  require_once "conecta.php";
  require_once "funcoes.php";

  $curtida = $_POST['curtida'];

  curtir($conexao, $curtida);

  header("Location: index.php");

?>

funcoes.php

<?php

  function curtir($conexao, $curtida) {

    $query = "update curtida set curtidas= $curtida";

    return mysqli_query($conexao, $query);
  }
    
asked by anonymous 19.09.2017 / 19:04

1 answer

1

You can simply change the update :

function curtir($conexao, $curtida) {

    $query = "update curtida set curtidas = curtidas + 1";

    return mysqli_query($conexao, $query);
  }
    
19.09.2017 / 19:08