我是PHP的学生,我在android中构建了一个应用程序,可将任何数据保存在Mysql BD中,但是我在TIMESTAMP上存在问题,它可以保存以下日期,如0000-00-00 00:00:00,附加我的php代码。
我测试了另一个php文件和android应用,正确发送了日期
PHP代码
$db = new DbOperation();
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST'){
//crear datos tabla registro
require 'php_tracker_server/conn.php';
registro();
//hecking the required params
if(isset($_POST['title']) and isset($_POST['message']) and isset($_POST['r_cel'])){
//creating a new push
$push = null;
//first check if the push has an image with it
if(isset($_POST['image'])){
$push = new Push(
$_POST['title'],
$_POST['message'],
$_POST['image']
);
}else{
//if the push don't have an image give null in place of image
$push = new Push(
$_POST['title'],
$_POST['message'],
null
);
}
//getting the push from push object
$mPushNotification = $push->getPush();
//getting the token from database object
$devicetoken = $db->getTokenByr_cel($_POST['r_cel']);
//creating firebase class object
$firebase = new Firebase();
//sending push notification and displaying result
echo $firebase->send($devicetoken, $mPushNotification);
}else{
$response['error']=true;
$response['message']='Parameters missing';
}
}else{
$response['error']=true;
$response['message']='Invalid request';
}
echo json_encode($response);
function registro() {
global $connect;
$cel = $_POST[ "r_cel" ];
$titulo = $_POST[ "title" ];
$fecha_r = $_POST[ "date" ];
$msj = $_POST[ "message" ];
//$query = "update escolar_tracker set latitude='$latitude',longitude='$longitude',date='$date',estado='$estado',speed='$speed' where ruta='$ruta' and jornada='$jornada'";
$query = "Insert into table1 (cel, titulo, fecha_r, msj) VALUES ('$cel','$titulo','$fecha_r','$msj')";
mysqli_query( $connect, $query )or die( mysqli_error( $connect ) );
mysqli_close( $connect );
}
答案 0 :(得分:0)
首先,我在问题格式和SQL注入方面同意Ed Cottrell。
第二,如何配置mysql中的字段?您必须为“时间戳记”或“日期时间”设置默认值,以便在不传递值时自动更新。
更多信息在这里: https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html