Jump to content

Recommended Posts

I have a php and jquery like system that doesn't work for some reason? When i click on the button to like it does nothing not even gives me an error please help thank you ! Here is my code that I am using and maybe you will see something that I didn't? The first part of the php code works it shows the like button so I know that's right but when you click it, it does nothing ...


PHP:



$likes = mysql_query("SELECT lid FROM likes WHERE uid='$id' AND imid='$photoid'");
if(mysql_num_rows($likes)==0){
$likethis = '<a href="#" id="'.$photoid.'" title="like"><div class="like"></div></a>';
}else{
$unlikethis = '<a href="#" id="'.$photoid.'" title="unlike"><div class="unlike"></div></a>';
}

JQUERY:



<script type="text/javascript">
$(document).ready(function(){
$(document).bind('click', '.like', function(){
if($(this).attr('title')=='like'){
$.post('like.php',{imid:$(this).attr('id'),action:'like'},function(){
$(this).text('unlike');
$(this).attr('title','Unlike');
});
}else{
if($(this).attr('title')=='unlike'){
$.post('like.php',{imid:$(this).attr('id'),action:'unlike'},function(){
$(this).text('like');
$(this).attr('title','like');
});
}
}
});
});
</script>

like.php:



$imid=$_POST['imid'];
$action=$_POST['action'];
if ($action=='like'){
$sql= mysql_query("SELECT * FROM likes WHERE imid=$imid and uid=$id");
$matches=$sql->rowCount();
if($matches==0){
$sql= mysql_query("INSERT INTO likes (imid, uid) VALUES($imid, $id)");
$sql= mysql_query("UPDATE photos SET likes=likes+1 WHERE id=$imid");
}else{
die("There is No Image With That ID");
}
}
if ($action=='unlike'){
$sql= mysql_query("SELECT * FROM likes WHERE imid=$imid and uid=$id");
$matches=$sql->rowCount();
if ($matches!=0){
$sql=mysql_query("DELETE FROM likes WHERE imid=$imid AND uid=$id");
$sql=mysql_query("UPDATE photos SET likes=likes-1 WHERE id=$imid");
}
}

Link to comment
https://forums.phpfreaks.com/topic/287684-php-like-system/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.