在Drupal中的数据库中插入数据

时间:2011-03-15 13:18:38

标签: php sql drupal

我想在mysql中插入一个结果,我使用这个查询:

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

这是错误:

* 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.`

有人有个主意吗?谢谢!

2 个答案:

答案 0 :(得分:1)

您可能正在寻找REPLACE,它将根据记录的主ID是否存在来更新或插入。

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

但是,坦率地说,你提到了Drupal,它有一个很好的帮手:http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_write_record/6

答案 1 :(得分:0)

您需要更新查询

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