Jump to content

[SOLVED] Am I being an idiot here?


fri3ndly

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.