doudou201701 2015-10-04 20:52
浏览 214

$ wpdb-> update()无效

I am modifying an existing plugin by creating an extension to it. I am trying to update a row with basic info just to test to see if the $wpdb->update works, but even using plain values it seems to get stuck. Please take a look at this image. The form keeps showing the working symbol but when I look in the database a new row has already been created, so the post went through. I think it is getting stuck on my lines of code below. I read some other similar questions on this website where people solved the problem by putting the $data and $where terms into variables, so I did that. It made it easier to read, but it doesn't seem to fix my problems.

$amount_field_col = array('post_amount' => '12.15');
$where_clause = array('ID' => '30');
$wpdb->update('wp_posts', $amount_field_col, $where_clause);

Any idea why it might not be updatig the row and why it could be getting stuck? The overall goal here is that I made a new field to an existing form and I want to be able to take inputs to the form and plug it into a new column I made in PHPMyAdmin called post_amount.

  • 写回答

1条回答 默认 最新

  • doumeng2637 2015-10-04 21:39
    关注

    I think I figured it out. The function that this code is in did not have global $wpdb; declared. I simply added that in above my code and it correctly update the row with ID = 30.

    Question for more experienced people - So by default, does each function forget about all other variables previously declared, even GLOBALS? I see in this plugin code that this variable was declared in its activation.php file, so I thought it would "remember" that $wpdb was declared.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?