I’ve had an issue that’s been bugging me for a while now. I don’t know if I’m being blind or stupid but I have a MySQL query embedded in a php page. When it executes, nothing happens! This is the query:
INSERT INTO objective (IdUser, CreationYear, Description)
VALUES ('$idFor','$date','$textAreaObjective1a')
I decided to echo the query out and it produces the full line of text that I need. When I copy and paste the line straight into MySQL it executes the query adds the row to the database.
INSERT INTO objective (IdUser, CreationYear, Description)
VALUES ('2', '20130314', 'hello 1')
EDIT Here is the PHP code used for the insert –
$objectiveCreation = mysql_query("
INSERT INTO objective (IdUser, CreationYear, Description)
VALUES ('$idFor','$date','$textAreaObjective1a')");
So the issue is, why can’t php handle the command? I’ve tried putting all values in quotations and removing all quotations. Echoing out the command then copy and pasting it manually resolves it and adds the data so the query seems to be fine. I added the mysql_error() command just after the query and it return the following error:
Unknown column 'CreationYear' in 'field list'
The column is in the database. Here is the structure:
IdObjective int(10)
IdUser int(10)
PercenOfComp float
CreationYear date
Description text
Status varchar(45)
Did you try
You can also open phpmyadmin and use the insert function (in horizontal menu bar when vieuwing a table) and fill in the fields press go and copy the query as shown.