if (!empty($_POST['like'])) {
$sql = "UPDATE Post set lcount = lcount + '1'";
$result=mysql_query($sql);
if (!$result) {
printf("Error: %s
", mysqli_error($con));
exit();
}
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
echo "<input type = 'submit' value = 'like' name='like'/>";
echo "</form>";
Trying to add like button like FB but my query is throwing an error. Lost please help. It is not displaying any detail error. Just writes error on my page...But I think its the query... Is my query right?
Your "error" most likely lies in your query statement.
$sql = "UPDATE Post set lcount = lcount + '1'";
By wrapping it in single quotes('
), you're casting your number 1
as a string. MySQL can't possibly know how to add a string to an integer.
Instead, pass the number itself and not the string representation:
$sql = "UPDATE Post set lcount = lcount + 1";