This script is supposed to get the current popularity from Mysql, add one digit to that number then update it. But this isnt happening and it only returns ‘6’ Any idea why?
Source:
<?php
include_once("../scripts/config.php");
$url = mysql_real_escape_string($_POST['url']);
preg_match("/id=(\\d+)/", $url, $matches);
$like = $matches[1];
$current_pop = mysql_query("SELECT pop FROM likes WHERE id=$like") or die ("Query failed: " . mysql_error());
$one = '1';
$pop = $current_pop + $one;
print $pop;
$update = mysql_query("UPDATE likes SET pop = ".$pop." WHERE id = ".$like."") or die ("Query failed: " . mysql_error());
?>
You need to use mysql_fetch_array() to get the value from the first row:
You could, however, update the pop value with just one SQL query: