error creating simple like button

1

I'm trying to create a simple like button that simply adds a +1 to a table in col like, ignoring that it can click more than once and that it is subject to invasion because it's just a test. The way it is now it gives me the following errors:

  

Undefined index: type in
  Undefined index: tab in
  Undefined index: state in C: \ wamp64 \ www \ new \ logado \ local \ coleta2.php
  Undefined variable: varsql in
  mysqli_query (): Empty query in

The php page that does the like update redirects to the same page that the button is, because this page receives values from another page, so I think there are these errors, but I tried to send the same data by like.php but it continues giving problem. if someone can help with the code or give another suggestion to make a button that adds +1 in a column referring to a specific id.

insira o código aqui<?php

        ob_start(); 

      $tipo =$_GET["tipo"];
      $tab = $_GET["tab"];

      include "coleta2.php";
      $conexao = mysqli_connect("127.0.0.1","root","","db_tcc") or die ("Não foi possível se conectar com o servidor.");


        echo "<meta charset='utf-8' />";






        switch($tipo){
            case "0":
                    $varsql = "SELECT * FROM $tab ORDER BY likes DESC";
                    break;

            case "1": case "2": case "3":
                    $varsql = "SELECT * FROM $tab WHERE TIPO='$tipo' ORDER BY likes DESC";
                    break;
    }





      function Like() { 
   $updd = "";
  $x = 0;
        if ($x == 0) {
          $x = $like + 1;
          $updd = "UPDATE $tab set likes = '$like'+1 where ID = '$id'";

        } else {
          $x = $like - 1;
          $updd = "UPDATE $tab set likes = '$like'-1 where ID = '$id'";

        }
        mysqli_query($conexao, $updd);
       }







       $carregar_guias = mysqli_query($conexao, $varsql);

echo "<div class='loc'>";

      while ($linha = mysqli_fetch_array($carregar_guias))
      {
        $id = $linha["id"];
        $blob = $linha["foto"];
        $nome = $linha["nome"];
        $desc = $linha["descricao"];
        $like = $linha["likes"];

       $img = imagecreatefromstring($blob); 

        ob_start(); 
        imagejpeg($img, null, 80);
        $data = ob_get_contents();
        ob_end_clean();




        echo "<table class='tablel'><tr>";
        echo "<td>".  htmlentities(utf8_encode($nome), 0, "UTF-8")."</td>";  
        echo "<td> <form name='like' method='get' action='like.php?            tab=$tab&id=$id'><INPUT TYPE='submit' VALUE='Curtir' ></form></td>
        <td>$like </td></tr>
        <tr><td colspan='3' class='imag'>";

          echo '<img  src="data:image/jpg;base64,' .  base64_encode($data)  . '" class="imag"  />';

        echo "</td></tr>
        <tr><td class='desc' colspan='3'  >".  htmlentities(utf8_encode($desc), 0, "UTF-8")."</td></tr>
        </table><br>";



      }
      echo "</div>";
    ?>

pag like.php

<?php

$id =$_GET["id"];
      $tab = $_GET["tab"];
      $tipo = $_GET["tipo"];

$conexao = mysqli_connect("localhost","root","","db_tcc") or die ("Não foi possível se conectar com o servidor.");
$updl = "UPDATE $tab set likes = likes +1 where id = '$id'";
mysqli_query($conexao, $updl);

header('location:din.php');

?>
    
asked by anonymous 06.11.2017 / 16:33

1 answer

0

Try removing the following lines from the like function:

 $x = $like + 1;

$x = $like - 1;

and put this:

 if($x == 0){
      $updd = "UPDATE $tab set likes = likes + 1 where ID = '$id'";

    } else {
      $updd = "UPDATE $tab set likes = likes - 1 where ID = '$id'";

    }
    mysqli_query($conexao, $updd);
    
06.11.2017 / 18:19