Like/Dislike-Script only once per user.

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' ) {
//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)
}