首页 > 解决方案 > PHP:替换数据库中的现有日期

问题描述

我正在尝试删除当前日期并使用新日期对其进行更新,以表明它是最新版本。发生这种情况时不会在 DB 表中创建新条目。以下内容用于更新信息的其他部分,但日期本身在最初插入数据库后不会更新。我一直在尝试不同的东西,但没有什么是完全正确的。有什么建议么?谢谢。

if(isset($_POST['productId'])) {
    $productId = $_POST['product'];
    $userId = $_POST['userId'];
    $teamplay = $_POST['teamplay'];
    $date = date("Y-m-d H:i:s");

    if( $database->has('teamplays', [
        'AND' => [
            'productId' => $productId,
            'userId' => $userId
            
            
        ]
    ]) ) {
        $database->update('teamplays', [
            'teamplay' => $teamplay,
        ], [
            'productId' => $productId,
            'userId' => $userId
            


            
        ]);
    } else {
        $database->insert('teamplays', [
            'teamplay' => $teamplay,
            'productId' => $productId,
            'userId' => $userId,
            'teamplaydate' => $date
            
        ]);
    }
}

标签: phpdatabaseinsert-update

解决方案


推荐阅读