I have an issue with my SQL query.
I am trying to transfer data between two tables using PHP and I can't wrap my head around how to fix this.
My code looks like this:
$newValue = "test";
mysql_query("INSERT INTO `table2` (`value1`, `value2`, `value3`, ..., `valueX`) SELECT `value1`, `value2`, `value3`, ..., `$newValue` FROM `table1`")
valueX in the INSERT INTO is meant to be the table that doesn't exist in table1.
What I'm having issues with is that if the $newValue is a number, for instance 2, the query works as intended. Allthough if I instead use a string, like in the example above, the query fails and I get the Unknown field error.
Could this have to do with that it tries to find a column with the $newValue name since it's a string and it doesn't do this if it's an integer? If so, is there a way to make it so I can add this static value in this query without it thinking that it's another column?
EDIT: My problem was fixed by replacing ` with ' at SELECT $newValue.