doushenmao9036
2014-01-01 12:36
浏览 54
已采纳

PHP MYSQL更新多个字段,包括DATETIME字段

I can update the field 'delivered' from 0 to 1 no problem but when I try to update 'delivered_time' nothing happens in the database. This may be to do with the way I am writing the code but If anybody could help I would really appreciate it, thanks!

if (isset($_POST['delivered']) === false) {
                mysql_query("UPDATE `listings` SET `delivered_time` = '{$date->format('Y-m-d H:i:s')}' AND `delivered` = 1 WHERE `order_id` = $order_id");
}

I have also tried this but this did not work either

if (isset($_POST['delivered']) === false) {
                    mysql_query("UPDATE `listings` SET `delivered_time` = NOW() AND `delivered` = 1 WHERE `order_id` = $order_id");
} 

My MYSQL database is set to have 'delivered' defined to 0 and is stored as an INT value. The 'delivered_time' field is stored as a DATETIME value in the database.

图片转代码服务由CSDN问答提供 功能建议

我可以将“交付”字段从0更新为1没问题,但是当我尝试更新'deliver_time'时没有 发生在数据库中。 这可能与我编写代码的方式有关但如果有人可以提供帮助我会非常感谢,谢谢!

  if(isset($ _ POST ['deliver'  ])=== false){
 mysql_query(“UPDATE` listings` SET`referred_time` ='{$ date-> format('Ymd H:i:s')}'和`deliver` = 1 WHERE`  order_id` = $ order_id“); 
} 
   
 
 

我也尝试了这个,但这不起作用

   if(isset($ _ POST ['deliver'])=== false){
 mysql_query(“UPDATE` listings` SET`referred_time` = NOW()AND`veryed` = 1 WHERE`order_id` = $  order_id“); 
} 
   
 
 

我的MYSQL数据库设置为”已传递“定义为0并存储为INT值。 'delivered_time'字段作为DATETIME值存储在数据库中。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dousao6313 2014-01-01 12:41
    最佳回答

    Try this code

    <?php
    
    if (isset($_POST['delivered']) === false) {
        mysql_query("UPDATE `listings` SET `delivered_time` = NOW(),`delivered` = 1 WHERE `order_id` = ".$order_id);
    }
    ?>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题