Hi everyone,
I'm developing a module and I have to do some queries. I installed the table in the database (it has two columns), and that goes fine. Then I want to add a line in the table so I use the following code:
db_query("INSERT INTO {owners2} (test, oid, book) VALUES (%s, %s, %s)", 'test', $user->name, $node->title);
But I keep getting an error message in drupal, allthough it works when I write that code in phpmyadmin. This is the error message I get:
# user warning: Unknown column 'Gwenn' in 'field list' query: INSERT INTO owners1 (test, oid, book) VALUES (test, Gwenn, Shantaram)
I read on a post that switching the order of the columns could help, did that and it didn't help. At first the error message always came on the first column, no matter the content, so i added a new column in first position ('test'), but then the error jumped to the 2nd position...as you can see.
I have really no idea what it's doing, or why...
Can anyone help?
Thanks
Comments
Quote your strings
You're trying to insert strings (liket
Gwenn) into an SQL query without quoting them (likeVALUES ('%s', '%s',. That doesn't work.sorry, i'm new at this...
should I even put $user->name between quotes? Because I figured that since the error message said 'Gwenn' that part of the code worked...
And I tried putting strings in between quotes in the code, but it didn't help... I'll try it again though, you never know...
Thanks
i think your error is
i think your error is somewhere else..
Your posted query was "iNSERT INTO {owners2}..."
while the error was in owners1 ..
Also put quotes in between placeholders and not the actual values..
'%s'
THANKS
That did the trick!
It's now moved on to another error, but at least it's inserting into the table...