开发者

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 s开发者_JS百科yntax 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!


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


You need an update query

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜