Jump to content
Fórum Script Brasil
  • 0

Opção Curtir


Marcos Guiga

Question

Bom pessoal criei um script simples para dar a opção "curtir" ao seu site, a instalação é simples crie no banco de dados as tabelas id,nome, email, post, data e curtidas(com o valor de zero) e crie o respectivo cadastro das postagens.Para exibir as postagens crie uma pagina chamada postagem.php?id=(id da postagem)

<?php  session_start(); require("../configs/connection.php");


$id = $_GET['id'];
$posts = $mysqli->query("SELECT * FROM postagens WHERE id='$id'");
while($post = $posts->fetch_array()){
echo "$post[nome]:  <br> $post[post] <br> postado em:$post[data]";
if($perm==1){
echo "<br><a href='?action=deletar&id=$post[id]'>deletar</a><br><br>";
echo "vc tem $post[curtidas]";
}
}


if(isset ($_POST['curtida'])){
$_SESSION["curtir"] = 1;
$posts = $mysqli->query("SELECT * FROM postagens WHERE id='$id'");
while($post = $posts->fetch_array()){
$curtida = $post['curtidas'];
$curti =  $curtida + 1;
$mysqli->query("UPDATE postagens SET curtidas = '$curti' WHERE id = '$id'");
}


}


if(isset ($_POST['curtido'])){
$posts = $mysqli->query("SELECT * FROM postagens WHERE id='$id'");
while($post = $posts->fetch_array()){
$curtida = $post['curtidas'];
$curti =  $curtida - 1;
$mysqli->query("UPDATE postagens SET curtidas = '$curti' WHERE id = '$id'");
}


}
if(isset($_SESSION["curtir"]) AND $_SESSION["curtir"] == "1" ){
echo"<form action='' method='post'>
<input type='submit' name='curtido' value='Descurtir'>
</form>";unset($_SESSION['curtir']);
}else{
echo"<form action='' method='post'>
<input type='submit' name='curtida' value='Curtir'>
</form>";
}

?>

espero ter ajudado, qualquer melhora é bem vinda!

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      652k
×
×
  • Create New...