I have the following code which updates a field in a database table to add 1 to it. The ID should have a variable being posted to it. Can anyone see where this is going wrong?
EDIT: Sorry, I completely forgot to mention the actual problem. The database is not updating the field.
<?php
$con=mysqli_connect("localhost","**","***","***");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"UPDATE base SET thumbdown = thumbdown + 1 WHERE id = $_POST['id']");
mysqli_close($con);
?>
You wont get the $_POST['id']
parsed in to the string correctly as it is an array. You must enclose it in braces:
"UPDATE base SET thumbdown = thumbdown + 1 WHERE id = '{$_POST['id']}'"
But remember (always!) to escape the variable first:
$id = mysqli_real_escape_string($_POST['id']);
mysqli_query($con,"UPDATE base SET thumbdown = thumbdown + 1 WHERE id = '{$id}'");