$time=date("G:i:s j.n.Y");
$wholetime="$time";
mysql_query("INSERT INTO rivase_chat_posts SET sender='$user', content='$msg', time='$wholetime', 'to'='$affectuser'");
$msg="";
I am doing a private chat thing. That is my code. It results this error:
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 ”to’=’gs” at line 1
($user=”gskartwii”, $msg=”HI”,
$affectuser=’gs’)
For column names, use backticks rather than single-quotes:
Single quotes are there for strings only. Backticks (normally left of the number 1 on your keyboard) are the things to use for column or table names in mysql.
Edit: As Michael Berkowski correctly points out, the reason you have to do this for the column name is because
tois a reserved word in mysql – which is a lovely way of saying that it is a special word that mysql sees to mean something within a query normally. on that note, it really might not be the best idea to use the reserved words as columns in your table – you will have to backtick them in every single instance that you use them. You might want to consider renaming it to something liketoUserwhich will probably make the rest of your project easier to SQL out 🙂