Answer the question
In order to leave comments, you need to log in
How to correctly write date to mysql table or what is wrong?
I am getting in js const date = Date.now(); and throw it through ajax in php code
<?php
require_once "db.inc.php";
function clearStr($data){
global $link;
return mysqli_real_escape_string($link, trim(strip_tags($data)));
}
function clearInt($data){
return abs((int)$data);
}
function updateTask($task, $date){
global $link;
$status = 0;
$sql = "INSERT INTO tasks (text, status, timetask) VALUES (?, ?, ?)";
if ($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "sii", $task, $status, $date);
mysqli_stmt_execute($stmt);
$rows = mysqli_stmt_affected_rows($stmt);
return $rows;
}
return $stmt;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
if (isset($_POST['add'])){
$task = clearStr($_POST['task']);
$date = $_POST['date'];
$res = updateTask($task, $date);
echo $_POST['date'];
// echo $res;
}
}
Answer the question
In order to leave comments, you need to log in
It would be necessary to choose a different type of field, got out of the INT limits:
INT or INTEGER - integers of ordinary capacity - range of signed numbers: -2147483648 ... 2147483647, unsigned - 0 ... 4294967295
Thank you. It's always like that, you think about one thing, but in reality it's another)))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question