145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

I’ve tried it on my own now and I’m close to a solution. Maybe someone could help me with the final step? Maybe someone who could need it too?

So, I have a FB Login Plugin ( http://www.sociable.es/facebook-connect-wordpress-plugin-screenshots/ ) And an Ajax Like/Dislike Script ( http://www.phpkobo.com/doc.php?d=install&p=AL201-102 )

You could download all the important files with all my changes here: http://markenkampf.com/likedislike.zip

Logged in Users (via facebook) should be able to vote only once, That’s why I’m writing the user id + page id in a sql table. If the same user id wants to vote the same page id, again it doesn’t work.

My only problem that needs to be solved: If the user clears the cookies after his first vote, he could vote a second time. But NOT a third or fourth time. The problem is that the PHP code doesn’t wait until the MYSQL request is finished.

I tried to build workaround in the JS file, but I’m not very good in it and so the code looks too complex for me.

Thanks a lot.

(it also needs to be fixed that a user who isn’t logged in, can’t vote. but that’s no problem for me)

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Does anyone have a solution for this? The if ( $voteaccepted == ‘yes’ ) { at the bottom doesn’t work because SQL is too slow.

if ($_REQUEST['buttonclick'] == "yes" ) {
    $con = mysql_connect('mysql5.loveless.businesspage.at', 'db381825', 'rBTFTGHv');
    if (!$con)
    {
      die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("db381825", $con);

    $userid = $_REQUEST["userid"];
    $pageid = $_REQUEST["pageid"];

    $einlesen = mysql_query("SELECT COUNT(*) FROM a1wbabs_votelock WHERE wp_id=$userid AND page_id=$pageid");
    if(mysql_result($einlesen,0)<1) { 
        $voteaccepted = "yes";
        mysql_query("INSERT INTO a1wbabs_votelock (wp_id, page_id)
        VALUES ($userid, $pageid)");
    } else {
        $voteaccepted = "no";
    }    
    mysql_close($con);            
}
// LLD END

//-- add votes
if ( $voteaccepted == 'yes' ) {
<strong>//THIS SHOULD ONLY HAPPEN ONCE but it's possible to get there a second time because the variable $voteaccepted is not set after the first time (SQL is too slow)</strong>
}
3435 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Volunteer moderator says

I don’t think your $voteaccepted variable is in scope at the point at which you test it based on this code. You probably just need to declare/initiaize the variable prior to the first if statement.

MySQL queries are synchronous so there shouldn’t be any race condition (which I assume is what you mean by SQL being too “slow”) here.

I’d recommend using booleans or at least constants in your code, rather than strings.

Also, if this is for WordPress, you should definitely be using the WordPress database functionality.

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Thank you for your help.

Hm I can’t get it to work. I tried to put the code everywhere in the php file. For some reason I can’t use global variables in this file – The Like Script would work anymore.

Additionally, for some reason booleans, as you mentioned, doesn’t work. Maybe because of this code in the JS file:
 $.post( this.url_server,
            { cmd: "vote", tid:this.tid, vote:v, userid:this.userid, pageid:this.pageid, buttonclick:this.buttonclick, voteaccepted:this.voteaccepted },
            function(data) { 

I’m trying to fix the problem for the whole day now. I think it’s too hard for me. I have problems with the understanding of the order the code runs and there is much code I haven’t seen before.

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

I haven’t changed it to the wpdb yet because it’s in a folder in the wordpress root and not really in wordpress. I want to fix the other issue before I learn the use of the wpdb function. Or Do you think my Main issue is because I don’t use wpdb?

Thank you

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

I’ve Finally Found the error! It had to be ($einlesen,0)<0) instead of ($einlesen,0)<1)

Now, I have another question (jquery). I have two jquery functions .

$(document).ready(function() {
    $( '.ld-container' ).each( function(){
        var buttonclick = 'no';
        var voteaccepted = 'yes';
        var obj = new CAjaxLikes( this,buttonclick,voteaccepted ); 
        obj.run();
    });
    $( '.ld-container .button' ).click( function(){
        var buttonclick = 'yes';
        var voteaccepted = 'yes';
        var obj = new CAjaxLikes( this,buttonclick,voteaccepted ); 
        obj.run();
    });
});

The Problem is that if I click one of the Submit Buttons, the each function AND the click function run.

But I want the each function to only run on page load. If a Submit button is clicked, only the click function should run. This is the HTML:

<div class="ld-container" tid="demo4" userid="<?php" echo=""> pageid=<?php the_ID(); ?> action='http://xxx.de/poll/ajax_likes.php'>

<form>
    <input type="submit" class='button ld-btn-like' title='Kontrahent 1' value='<?php echo $team1; ?>' tid='demo4' userid=<?php echo $userid; ?> pageid=<?php the_ID(); ?> team=1 action='http://xxx.de/poll/ajax_likes.php'>

    <span class="jetztabstimmen">Jetzt abstimmen</span>

    <input type="submit" class='button ld-btn-dislike' title='Kontrahent 2' value='<?php echo $team2; ?>' tid='demo4' userid=<?php echo $userid; ?> pageid=<?php the_ID(); ?> team=2 action='http://xxx.de/poll/ajax_likes.php'>
</form></div>
194 posts Dreams Money Can Buy
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has referred 200+ members
  • Has collected 10+ items on Envato Market
+5 more
SwiftIdeas says

EDIT: Seems I didn’t actually read the thread post! :doh:

- Ed

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Maybe it’s not the best solutions with the action attribute in the div and in the buttons. But the plugin was built in that way and I don’t want to change it if not necessary.

So is there a way to don’t run the each function when a submit buttpn is clicked?

by
by
by
by
by
by