Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The technical problem is this line:</p> <pre><code>$.get("./scripts/likecounter.php", {_choice : choice, _site : site, _id : id}... </code></pre> <p>as site and id are undefined you'll be getting a javascript error <code>ReferenceError: site is not defined</code></p> <p>Try:</p> <pre><code>$.get("./scripts/likecounter.php", {_choice : choice, _site : "&lt;?php echo $site; ?&gt;", _id : "&lt;?php echo $imgid; ?&gt;"}... </code></pre> <p>You don't need the hidden inputs, also <code>onClick</code> should be <code>onclick</code>.</p> <p>Other quick suggestions:</p> <p>Make sure $imgid is actually an integer:</p> <pre><code>$imgid = intval($_GET['_id']); if($imgid == 0) exit('Invalid id'); </code></pre> <p>The following doesn't need to be separate:</p> <pre><code>$likes = $mysqli-&gt;query("SELECT like FROM $table WHERE id = $imgid"); $dislikes = $mysqli-&gt;query("SELECT dislike FROM $table WHERE id = $imgid"); $result = $mysqli-&gt;query("SELECT like_count, dislike_count FROM $table WHERE id = $imgid"); </code></pre> <p><code>$mysqli-&gt;query</code> will only return a mysqli_result, meaning you can't just echo it out, you'll have to do a fetch, and because you know you are only getting a single result you can just use <code>list($likes, $dislikes) = $result-&gt;fetch_array(MYSQLI_NUM);</code></p> <p>Have a read of the <a href="http://php.net/manual/en/mysqli-result.fetch-array.php" rel="nofollow">docs</a> to help you understand what the heck I'm going on about.</p> <p>As you mentioned people can just keep hitting like/dislike all they want, you'll need to limit this with an IP log of some sort. For example setup a new database table with the following fields; ip, table, imgid. Then when someone "likes" log their IP:</p> <pre><code>$sql = "INSERT INTO xxx (ip, table_name, imgid) VALUES(\"".$_SERVER['REMOTE_ADDR']."\", \"$table\", $imgid)"; $mysqli-&gt;query($sql); </code></pre> <p>Then check if they have a record before adding a new like:</p> <pre><code>$sql = "SELECT ip FROM xxx WHERE ip = \"".$_SERVER['REMOTE_ADDR']."\" AND table_name = "$table" AND imgid = $imgid"; $result = $mysqli-&gt;query($sql); if($result-&gt;num_rows == 0) { ...if($input ==... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload