dongzhong9055 2019-02-05 00:54
浏览 105
已采纳

单击按钮后,将数据库的值更改为当前日期和时间

How do I update the value of status with the current date and time after clicking the complete button?

Example:

Status = 02/05/2019 8:54 AM

So far this is what I've tried:

<?php

     if(isset($_POST['completed']))
    {
        $msg = "Completed";
        $status = $_POST['completed'];
    }

    $reqnumber=$_POST['reqnumber'];
    $con = mysqli_connect('localhost', 'root', '');
    mysqli_select_db($con, 'pcrequest');

    $sql = "UPDATE request SET status = '$status', status = 'date('Y-m-d H:i:s');' WHERE reqnumber = '$reqnumber'";

    if(mysqli_query($con, $sql))
        header("refresh:1; url=messages.php?msg=$msg");
    else
        var_dump(mysqli_error($con));
    
?>

</div>
  • 写回答

1条回答 默认 最新

  • dqwr32867 2019-02-05 01:06
    关注

    You are trying to set "status" twice. That semicolon and nested single quotes could cause some issues as well where you have the date() function.

    I would recommend setting the date outside of the query and inserting it as a variable, like this:

    $now = date('Y-m-d H:i:s');
    
    $sql = "UPDATE `request` 
        SET `status` = '$now' 
        WHERE `reqnumber` = '$reqnumber';";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵