views:

36

answers:

5

Hey... so I attempted to run the query below and it just won't do it. I've checked:

  • The number of fields in the form matches the number of fields in the table.
  • The number of session variables matches those numbers too.
  • That the actual query contains the data to be input with an echo.
  • That the table name is correct.
  • That queries work with other tables in the same database (they DO).
  • Used or die(mysql_error(); to get the "Incorrect syntax" error.
  • Rebuilt the table several times.

Here's the line that's apparently syntactically problematic, if you can see anything wrong with it or point me in the right direction I'd be super greatful as I'm at a loss now! Might it be a memory issue?

$sql = "INSERT INTO careBoiler (buyerID, date, sector, require, boilerMake, boilerModel, boilerType, heating, visit, deadline, budget, currcompany, specificreq) VALUES ('{$_SESSION['buyerID']}', now(), '{$_SESSION['cb']['sector']}', '{$_SESSION['cb']['require']}', '{$_SESSION['cb']['boilerMake']}', '{$_SESSION['cb']['boilerModel']}', '{$_SESSION['cb']['boilerType']}', '{$_SESSION['cb']['heating']}', '{$_SESSION['cb']['visit']}', '{$_SESSION['cb']['deadline']}', '{$_SESSION['cb']['budget']}', '{$_SESSION['cb']['currcompany']}', '{$_SESSION['cb']['specificreq']}')";
A: 

Looks like require is a MySQL reserved word which you are using as a column name.

To fix this you can either choose a different column name or place it in back ticks as:

$sql = "INSERT INTO careBoiler (buyerID, date, sector, `require`,...
                                                       ^       ^
codaddict
Yep, thanks! ;o)
Daniel Alexander Knox
+1  A: 

As a general php/mysql debugging strategy

  1. Print out the actual query, with the values inserted. Sometimes that alone will make the problem obvious.

  2. If you have it, copy + paste the query into phpMyAdmin / mysql workbench and see what error message it gives you. If you don't have access to either of those, just call mysql_error() in the php script and see what error it gives you.

Sam Dufel
Thanks but I did both prior to posting, as I said. Neither has helped the problem however! =/
Daniel Alexander Knox
In that case, why not post what was printed, rather than making people guess?
Sam Dufel
I posted the error in the title...?
Daniel Alexander Knox
A: 

Try using or die($sql.' - '.mysql_error()); to see what it thinks its processing.

BenWells
I've done that. - Got the error I put in the question, and I can find no syntax problem hence posting this question here.
Daniel Alexander Knox
See Sam Dufel's post, what you posted could output any sort of mysql error unkown to anyone trying to help if $_SESSION['cb']['sector'] = 'dave's something or other'Actually if you could also post a dump of the table structure if you update your post then I'll put it in a phpmyAdmin to have a look at.
BenWells
+2  A: 

It is a little difficult because you haven't provided the exact error message.

However, it could be that you use the column name 'require' which is a reserved keyword in MySQL. The keyword 'date' is also reserved but due to it's widespread use it's allowed.

Try changing the column name 'require' in your table and query.

Look here for more information; http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

If that's not it then please provide the full error message.

Mangotastic
THANK YOU! The error was I was using a reserved keyword and it's now fixed ;o)
Daniel Alexander Knox
A: 

type the field date like `date`

Sascha Presnac