-7

I'm using the below query to insert data into a MySQL database. But this not working. I'm also using this type query in my other page and that's working fine.

This is the SQL query:

$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, 'description') 
VALUES ('$url','$title', '$desc');";
$result=mysql_query($query);
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
febeena
  • 1
  • 3

2 Answers2

6

You used single quotes around description instead of backticks:

$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, `description`) VALUES ('$url','$title', '$desc');";

Standard disclaimer: Read up on PDO and MySQLi as mysql_x functions are deprecated.

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • Nice catch. Maybe a good reason why MySQL shouldn't use backticks for column name quoting. – siride Nov 01 '13 at 15:02
  • @siride Indeed, however are backticks absolutely necessary in cases like these? I take it that if one is going to use back ticks, they'd have to use them on ALL of them, or not use them at all? – Funk Forty Niner Nov 01 '13 at 15:04
  • Hi...Thanku so much.... – febeena Nov 01 '13 at 15:05
  • @Fred-ii- I'd advise to use them always, just to have consistent code and prevent errors caused by using a keyword as column name. – Sirko Nov 01 '13 at 15:06
  • @Sirko I agree 100% --- When in doubt in accidentally or unknowingly using a [reserved word](http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html). – Funk Forty Niner Nov 01 '13 at 15:07
  • Can you give the code for play videos.The url of videos stored in my mysql db – febeena Nov 01 '13 at 15:08
  • 1
    @febeena That is a completely different problem. Anyways, on SO we expect you to do some research first and try yourself. If you fail, you're welcome to open another question, showing your code and where you failed. – Sirko Nov 01 '13 at 15:10
1

Bad quoting:

$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, 'description') 
                                                             ^--         ^---

' quotes in SQL turn the quoted data into a string. This means you're using a string in a fieldname context, which does not work.

Marc B
  • 356,200
  • 43
  • 426
  • 500