仅当$ _POST值不为null时,WPDB才会更新

I'm updating a row in a database, however the fields passed by $_POST are not required fields, so they may not be passed at all, I'm updating my db row here

  $wpdb->update(
    'learning_evaluation_questions',
    array(
      'question_content' => $_POST['question'],
      'question_placeholder' => $_POST['placeholder']

    ),
    array(
      'id'=> $id
    )
  );

Which works fine, it updates the row - however if I haven't passed one of these values through $_POST it will set this value to null.

i.e.

'question_content' => NULL,

Anyway to conditionally check these to only update if !NULL?

EDIT: Sorry I should have explained that even if one of these is set I want to update, if they want to update just the question_placeholder - then I want to update that without the question_content value setting to NULL

查看全部
douqian5553
douqian5553
2015/06/01 14:23
  • wordpress
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信

0个回复