1
I’m trying to create a simple button like that simply adds +1 in a table in the col like, ignoring that you can click more than once and that is subject to invasion because it is only a test. The way it is now it returns me the following errors:
Undefined index: type in
Undefined index: tab in
Undefined index: state in C: wamp64 www new logged in sites collect2.php
Undefined variable: varsql in
mysqli_query(): Empty query in
The php page that makes the like update redirects to the same page that is the boot, because this apgina receives values from another page, so I think there are these errors, but I tried to send the same data by like.php but still giving problem. if anyone can help with the code or give another hint 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');
?>