I was writing some code to update one of my databases and figured it would be a lot easier to use variables then some long If/then statement, but i can't seem to figure out what's wrong with this code. Any help would be great.
<?php
$bought = $_POST['bought'];
$conn = mysql_connect("localhost", "root", "") or die('Could not connect to the database: '.mysql_error());
mysql_select_db("countries", $conn) or die('Could not select the database: '.mysql_error());
$sql = "UPDATE improvements SET $bought = yes WHERE CONVERT(Country using utf8) = '$ID' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error().'<p>SQL:<br />'.$sql.'</p>');
?>
The way i set it up, the choices in the previous form are the same as the field names of the table, so when the program recieves information from the form, i can make updates without a long if/then or switch statement
I've done this before in previous code, and that worked fine, so i know the sql query can handle variables.
Here's the exact error that it prints on the screen:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Force = 'yes' WHERE CONVERT(Country using utf8) = 'United States' LIMIT 1' at line 1
SQL:
UPDATE improvements SET Police Force = 'yes' WHERE CONVERT(Country using utf8) = 'United States' LIMIT 1