UPDATE table set date field

时间:2016-06-06 14:17:33

标签: php mysqli

I am trying to update a date field from a row but it does not seem to be affecting it but it is updating other columns as expected. I must be missing something when setting the date:

el.on({
'scaling': function(e) {
    var obj = this,
        w = obj.width * obj.scaleX,
        h = obj.height * obj.scaleY,
        s = obj.strokeWidth;

    obj.set({
        'height'     : h,
        'width'      : w,
        'scaleX'     : 1,
        'scaleY'     : 1
    });
}
});

The database is using the $task_id = $_POST['task_id']; $task_started_status = htmlspecialchars($_POST['task_started_status']); $task_start_date = date('Y-m-d'); // Attempt update query execution $sql = "UPDATE task_list SET task_started_status = $task_started_status, task_start_date = $task_start_date WHERE task_id='$task_id'"; if(mysqli_query($con, $sql)){ header('location: ../tasks.php'); } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($con); } data type but no errors occur it still believes its all valid - no errors - just not updating and if I DATE on the VAR_DUMP it outputs the date id expect it to be.

1 个答案:

答案 0 :(得分:3)

正如我在评论中所述:

需要在此处引用的

task_start_date = $task_start_date
task_start_date = '$task_start_date',因为它是一个字符串Y-m-d

另外,Y-m-d MySQL将其解释为2016减去06减去06(根据今天的日期)并且您正在使用的错误检查应该有抛出一个关于它的错误,但是你说它并不是我觉得奇怪的。

  

但没有出现错误,它仍然认为它全部有效 - 没有错误

在进行更新时,请使用mysqli_affected_rows()来表示真实性。

在标题后添加exit;。否则,您可能希望代码继续执行。

您可以使用CURDATE()代替$task_start_date = date('Y-m-d'); task_start_date = CURDATE(),而不需要使用引号。

您目前的代码向SQL injection开放。使用prepared statementsPDOprepared statements