I have a simple mysql table 
This is the code to connect to database and insert into testtable:
$mysqli = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "INSERT INTO testtable
VALUES (NULL, $forename)";
$res = mysqli_query($mysqli, $sql);
if($res === TRUE) {
echo "data successfully inserted.";
} else {
printf("Could not insert data: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);
}
In this case I try to insert $forename into my table. If I use a string literal like 'Jim' or '123' it gets inserted. If $forename is given the value 123 or any other number it gets inserted. If $forename = 'Jim' I get an error telling me there is no column 'Jim' as though I were specifying a column in the table.
It has happened to me before, you are missing quotes in the query. Try: