devolve_absolve wrote in php 😡grumpy

Listens: Nightwish - Nemo

This is really starting to bug me now, so I turn to you. This may seem so very stupid to some, so I apologise, but I just can't get it to work.

It's a very simple mysql insert query into a table with 4 fields, being user_id, subject_id, file_name, and article_date.

$insert = mysql_query(" INSERT INTO articles VALUES ('01', $subject, $filename, CURDATE()) ");

OK, looks fine on my end, I must admit. I've used the same query before with no problem whatsoever. I know it's connected to the database since I have been running a SELECT query after the above one to ensure there's no connection faults, and the manual entry I placed in there is being pulled out fine. If I use straight strings instead of variables, there is no problem at all with the insertion. So why could it possibly be choking on variables like this?

Googling has provided absolutely nothing except for the overwhelmingly confusing manuals and simple tutorials. Anybody else had this issue and/or know any fixes?


Edit: hrmm it appears to work if you have
$insert = "INSERT INTO articles VALUES ('01', $subject, $filename, CURDATE())";
mysql_query($insert);


If this is the answer, then great, though I do like to keep the number of lines of code to a minimum. Has it just been blind luck before?