开发者

Write form API values to database

I want to write Drupal F开发者_开发百科orm value made from API Form, to my database with the following code: Into my database only appears 1 and nothing more. What's wrong? Thanks!

$sql= "INSERT into {test} (id, studiejaar, opleiding, soortStage,
        stageplaats,periodes)VALUES(1, '%s', '%s', '%s', '%s', '%s')";
db_query($sql, $form['studiejaar']['#value'], $form['opleiding']['#value'], $form['soortStage']['#value'],
            $form['stageplaats']['#value'], $form['periodes']['#value']);


  • First, use $form_state['values']['studiejaar'] and so on instead of $form.

  • You probably shouldn't specific the id, instead, just leave that away and MySQL will automatically increment the value.

  • If you have defined your table with hook_schema() (what you need to do!), you could also use drupal_write_record().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜