简体   繁体   English

为什么Internet Explorer和Edge与其他浏览器将新的Date()数据输出到数据库不同?

[英]Why does Internet Explorer and Edge output new Date() data into database differently than other browsers?

I found a way to add a date as a time stamp when a user submits a message with my web application. 当用户使用我的Web应用程序提交消息时,我找到了一种添加日期作为时间戳的方法。 Every thing works perfectly but when I use new Date(); 一切正常,但是当我使用new Date(); to have its value store in a MySQL database, Internet Explorer and Edge just inputs the data like this ‎12‎:‎14‎ ‎PM but it suppose to look something like this 12:33 PM. 为了将其值存储在MySQL数据库中,Internet Explorer和Edge只是输入数据,例如“?12”:“ 14”和“ PM”,但它看起来像是这样的12:33 PM。

In other words different browsers input it perfectly in the database so I know my code isn't wrong but Edge and Explorer don't store the data properly so what's going on here? 换句话说,不同的浏览器将其完美地输入到数据库中,因此我知道我的代码没有错,但是Edge和Explorer无法正确存储数据,所以这是怎么回事? And how can I get Edge and Explorer to store the time data like how the other browsers do perfectly? 以及如何让Edge和Explorer像其他浏览器一样完美地存储时间数据? And this is a screenshot of the database. 这是数据库的屏幕快照。

屏幕截图

The method I'm using to store data into the database works perfectly with all different kinds of data like strings, numeric etc.. and all different browsers but edge and explorer can't store JavaScript new Date() value properly. 我用于将数据存储到数据库中的方法与所有不同类型的数据(例如字符串,数字等)以及所有不同的浏览器完美配合,但是edge和Explorer无法正确存储JavaScript新的Date()值。

Here is a method on how I'm getting a time stamp and generating values to be use in the server side code. 这是一种有关如何获取时间戳并生成要在服务器端代码中使用的值的方法。

message.js message.js

//Get message date
function message_date() {

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = mm + '/' + dd + '/' + yyyy;
var today;  
return today;
}  

var message_date_stamp = message_date();  // this will grab you the return value from message_date();

//Get user send message time
var timez = new Date();
timez = timez.toLocaleString('en-US', { hour: 'numeric',minute:'numeric', hour12: true });
var get_time = timez;

$(document).ready(function(){  
$("#send").click(function(){
var conversation_id = $("#conversation_id").val();
var user_id = $("#user_id").val();
var member_name = $("#member_name").val();
var message = $("#message").val();
var status= $("#status").val();
var sender_id= $("#sender_id").val();
var receiver_id= $("#receiver_id").val();
var photo_link = $("#photo_link").val();
var hyper_link = $("#hyper_link").val();
var date = message_date_stamp;
var time = get_time;

// Returns successful data submission message when the entered information is stored in database.
var dataString = 'conversation_id='+ conversation_id + '&user_id=' + user_id + '&member_name='+ member_name + '&message='+ message + '&status='+ status + '&sender_id='+ sender_id + '&receiver_id='+ receiver_id + '&photo_link='+ photo_link + '&hyper_link='+ hyper_link + '&time='+ time + '&date='+ date;

    //AJAX code to submit form.
    $.ajax({
    type: "POST",
    url: "send_message_data.php",
    data: dataString
    });
    });
    });

This is how I'm storing the data into the database in PHP just know that the value of new Date() is generated from a previous page and in PHP it's represented by PHP's variable call $time. 这就是我将数据存储在PHP中的方式,只是知道new Date()的值是从上一页生成的,而在PHP中,它由PHP的变量$ time表示。

send_message_data.php send_message_data.php

<?php
//Credentials
$db_servername = "localhost";
$db_username = "1234u";
$db_password = "1234";
$db_name = "1234db";

$connect = mysqli_connect($db_servername, $db_username, $db_password, $db_name);

//Form values
$conversation_id = $_POST['conversation_id'];
$user_id = $_POST['user_id'];
$member_name= $_POST['member_name'];
$message= $_POST['message'];
$status= $_POST['status'];
$sender_id= $_POST['sender_id'];
$receiver_id= $_POST['receiver_id'];

$date= $_POST['date'];

//FOR STACK OVER FLOW USERS $time is how I'm storing this into the data base  
$time= $_POST['time'];


$photo_link= $_POST['photo_link'];
$hyper_link= $_POST['hyper_link'];

//SECURITY

//Basic character escaping.
$conversation_id = htmlspecialchars($conversation_id);
$member_name = htmlspecialchars($member_name);
$message = htmlspecialchars($message);
$photo_link = htmlspecialchars($photo_link);
$hyper_link = htmlspecialchars($hyper_link);

//OTHER FEATURES 




//Prevent MYSQLI injection.
$conversation_id = mysqli_real_escape_string($connect, $conversation_id);
$member_name = mysqli_real_escape_string($connect, $member_name);
$message = mysqli_real_escape_string($connect, $message);
$photo_link = mysqli_real_escape_string($connect, $photo_link );
$hyper_link = mysqli_real_escape_string($connect, $hyper_link);

//Removes tags combat the following injections HTML, JAVA-SCRIPT, PHP.
$conversation_id = filter_var($conversation_id, FILTER_SANITIZE_STRING);
$member_name = filter_var($member_name, FILTER_SANITIZE_STRING);
$message = filter_var($message, FILTER_SANITIZE_STRING);
$photo_link = filter_var($photo_link, FILTER_SANITIZE_STRING);
$hyper_link = filter_var($hyper_link, FILTER_SANITIZE_STRING);


$query = "INSERT INTO messages_x1(conversation_id,user_id,member_name,message,status,sender_id,receiver_id,photo_link,hyper_link,date,time) values ('$conversation_id','$user_id','$member_name','$message','$status','$sender_id','$receiver_id','$photo_link','$hyper_link','$date','$time')";

$run = $connect->query($query);

if($run) {
echo "Form Submitted succesfully";
}

?>

And one last thing I read that it has nothing to do with the code but I read some where that mentions Explorer and Edge have problems on interacting with JavaScript's new Date() poorly in certain situations. 最后一件事,我读到它与代码无关,但是我读到了其中提到Explorer和Edge在某些情况下与JavaScript的new Date()交互不良的问题。 I just want a solution to bypass Explorer and Edge limitations. 我只想要一个解决方案来绕过Explorer和Edge的限制。

No offense to the people that said it was my code that had errors. 那些说我的代码有错误的人没有冒犯。 But I always knew it wasn't my code that was causing this. 但是我一直都知道不是由我的代码引起的。 I was right I found out that different browsers will tend to structure your code differently in your database. 我是对的,我发现不同的浏览器将倾向于在数据库中以不同的方式构造代码。 So for any future readers wondering why their code is treated and inserted differently in the data base then you know why. 因此,对于任何将来的读者,如果想知道为什么将他们的代码以不同的方式处理并插入到数据库中,那么您就会知道为什么。 Here is proof starting from internet explore to chrome and to safari Iphone. 这是从互联网探索到Chrome和Safari Iphone的证明。

Screen shot 屏幕截图

The good news is that internet explore version of the time is outputting the time in a human readable way but sadly it's structure of the time differs in the data base. 好消息是,Internet浏览时间以一种人类可读的方式输出时间,但是遗憾的是,时间的结构在数据库中有所不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 setImmediate和Internet Explorer以外的浏览器 - setImmediate and browsers other than Internet Explorer 为什么/在Chrome之前,Chrome与其他浏览器有何不同? - Why/how does Chrome treat onbeforeunload differently than other browsers? 为什么字符在 Internet Explorer 中“未定义”,而在其他浏览器中却没有 - Why characters are 'undefined' in internet explorer but not in other browsers jQuery无法在Internet Explorer中像在其他浏览器中一样工作 - jQuery not working in Internet Explorer as it does in other browsers 为什么&#39;string&#39;[0]在ie8 + IIS7.5上的行为与其他浏览器或本地文件不同? - Why does 'string'[0] behave differently on ie8 + IIS7.5 than other browsers or local file? Internet Explorer中的Bootstrap Accordion与其他浏览器功能不同 - Bootstrap Accordion in Internet Explorer does not function the same as other browsers $()在Internet Explorer中的工作方式不同吗? - Does $() work differently in Internet Explorer? 当我尝试调试ASP.NET程序时,为什么Internet Explorer(或其他浏览器)使用旧的JavaScript文件? - Why does Internet Explorer (or other browsers) use old JavaScript files when I try to debug my ASP.NET program? 为什么Edge浏览器不像其他浏览器那样处理Javascript setTimer() - Why Edge browser does not process Javascript setTimer() like other browsers 边缘、Internet Explorer 中新 WebSocket 的语法错误 - Syntax error on new WebSocket in edge, internet explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM