fri3ndly Posted June 7, 2008 Share Posted June 7, 2008 I have been stuck on this for an hour now, I just cant see the problem! <?php $query = "INSERT INTO news (title,desc,date) VALUES ('".mysql_real_escape_string($title)."', '".mysql_real_escape_string($desc)."', '".mysql_real_escape_string(date("Y-m-d"))."' )"; ?> The error I am getting when submitted is: 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 'desc, date ) VALUES ('Test', 'tes' at line 2 Quote Link to comment Share on other sites More sharing options...
T Horton Posted June 7, 2008 Share Posted June 7, 2008 Hi Try replacing this: date("Y-m-d") With something like this: date(\"Y-m-d\") Let me know how you get on. Best Regards Tom Quote Link to comment Share on other sites More sharing options...
fri3ndly Posted June 7, 2008 Author Share Posted June 7, 2008 Thanks for the reply. I tried that, however it makes the rest of the script unfuctional like text ie. like a closed apostrophe is missing. Do you think thats the part thats wrong then? Its strange because I have done many scripts in this way and its the first time I have seen this problem. I thought it may be a table or row name was wrong but iv checked them all a thousand times Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 7, 2008 Share Posted June 7, 2008 Don't use the PHP Date function. Use the MySQL NOW() function. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 7, 2008 Share Posted June 7, 2008 Back to your original sql syntax error, desc is a reserved mysql keyword. Change that column name to be something else. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted June 7, 2008 Share Posted June 7, 2008 add Ticks `desc` Quote Link to comment Share on other sites More sharing options...
.josh Posted June 7, 2008 Share Posted June 7, 2008 Back to your original sql syntax error, desc is a reserved mysql keyword. Change that column name to be something else. add Ticks `desc` To clarify: desc is a reserved mysql keyword, used to specify how to order results by (desc = descending order). You can use reserved words as column and table names by using backticks, but it is not really considered good programming practice to do so, as it increases chances for bugs (like now) and in general may cause confusion on your part. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 7, 2008 Share Posted June 7, 2008 Back-ticks are mysql specific. Using them results in non-standard sql and should you need to move your queries to a different sql database or mysql should more closely follow standards in the future, code that uses back-ticks will stop working. They should not be recommended as a solution. Quote Link to comment Share on other sites More sharing options...
fri3ndly Posted June 8, 2008 Author Share Posted June 8, 2008 Thanks everyone, so yes I was being an idiot. I will change the word desc to description. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.