Good afternoon! I was able to change the date on my site using the string “date_default_timezone_set (‘Europe / Moscow’);” Now the site shows the correct time, but when I register the user, the database shows another time zone of -4 hours. What should I do to make phpmyadmin create a user from +4 hours?
You cannot change the server date, however you can insert the correct date using PHP
How? I change time zone with help date_default_timezone_set (‘Europe / Samara’);
But the database leaves its time -4.
Code
<?php
ULogin(1);
date_default_timezone_set('Europe/Samara');
if ($_POST['enter'] and $_POST['text']) {
$_POST['text'] = FormChars($_POST['text']);
mysqli_query($CONNECT, "INSERT INTO `chat` VALUES ('', '$_POST[text]', '$_SESSION[USER_LOGIN]', NOW())");
exit(header('location: /chat'));
}
Head('Чат');
?>
Instead of NOW() replace it with
date("Y-m-d G:i:s")
So the code would be
<?php
ULogin(1);
date_default_timezone_set('Europe/Samara');
if ($_POST['enter'] and $_POST['text']) {
$_POST['text'] = FormChars($_POST['text']);
mysqli_query($CONNECT, "INSERT INTO `chat` VALUES ('', '$_POST[text]', '$_SESSION[USER_LOGIN]', ".date("Y-m-d G:i:s").")");
exit(header('location: /chat'));
}
Head('Чат');
This code not working. site crash
Any errors shown?
The entry does not appear in the database
Try this?
<?php
ULogin(1);
date_default_timezone_set('Europe/Samara');
$date = date("Y-m-d G:i:s");
if ($_POST['enter'] and $_POST['text']) {
$_POST['text'] = FormChars($_POST['text']);
mysqli_query($CONNECT, "INSERT INTO `chat` VALUES ('', '$_POST[text]', '$_SESSION[USER_LOGIN]', '$date')");
exit(header('location: /chat'));
}
Head('Чат');
1 Like
Yes! This working! Thanks!
1 Like
My pleasure to help
If you have any other issues, do not hesitate to open a new topic