prepare($SQL); $stmt->bind_param("sss", $link,$number,$desc); $link = $url; $number = 1; $desc = $title; $stmt->execute(); $stmt->close(); return get_vote($url); } function down_vote($url,$title){ global $mysqli; if($_COOKIE[md5($url)] == 1){ return; } setcookie(md5($url),"1", strtotime( '+180 days' ),"/"); $SQL = "INSERT INTO links (url, down_vote,title) VALUES(?,?,?) ON DUPLICATE KEY UPDATE down_vote=down_vote+1"; $stmt = $mysqli->prepare($SQL); $stmt->bind_param("sss", $link,$number,$desc); $link = $url; $number = 1; $desc=$title; $stmt->execute(); $stmt->close(); return get_vote($url); } function get_vote($url){ global $mysqli; $SQL = "SELECT up_vote,down_vote from links where url=?"; $stmt = $mysqli->prepare($SQL); $stmt->bind_param("s", $link); $link = $url; $stmt->execute(); $stmt->bind_result($up_vote, $down_vote); while ($stmt->fetch()) { printf ("%s,%s", $up_vote, $down_vote); } } # post to vote.php with "vote=up or down" and url and title if up or down switch($_POST['vote']){ case "down": down_vote($_POST['url'],$_POST['title']); break; case "up": up_vote($_POST['url'],$_POST['title']); break; default: get_vote($_POST['url']); } mysqli_close($mysqli);