user001
user001

Reputation: 471

Insert data in database in Drupal

I want to insert a result in mysql, i use this query:

$sql= "INSERT into {test} WHERE Id = $currentID (soortstage)VALUES('%s')";

that is the error:

* user warning:

You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near  `WHERE Id =
(Soortstage)VALUES('132')'` at line 1
query: `INSERT into test WHERE  Id =
(Soortstage)VALUES('132') in
C:\xampp\htdocs\testplanning\modules\planning\planning.module on line 425.`

* warning: 

Invalid argument supplied for
foreach() in
`C:\xampp\htdocs\testplanning\includes\form.inc
on line 1213.`

Have someone a idea? Thanks!

Upvotes: 0

Views: 2331

Answers (2)

berkes
berkes

Reputation: 27563

You might be looking for REPLACE, which will either UPDATE or INSERT based on whether or not the primary ID of the record exists.

REPLACE INTO {test} WHERE Id = $currentID (soortstage) VALUES('%s')

But, frankly, you mention Drupal, which has a nice helper for this: http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_write_record/6

Upvotes: 1

Gaurav
Gaurav

Reputation: 28755

You need an update query

$sql= "UPDATE {test} SET soortstage = '%s' WHERE Id = $currentID ";

Upvotes: 0

Related Questions