I can not change the time zone in the index.php file

I can not change the time zone in the index.php file
In this file I have all the functions, checks, SQL requests.
I’m setting the team up
date_default_timezone_set (‘Europe / Samara’);
$ date = date (“Y-m-d G: i: s”);
and I write the query:

<?php function SendNotice ($ p1, $ p2) { global $ CONNECT; $ Row = mysqli_fetch_assoc (mysqli_query ($ CONNECT, "SELECT` id` FROM `users` WHERE` login` = '$ p1' ")); if (! $ Row ['id']) echo 'Error'; mysqli_query ($ CONNECT, "INSERT INTO` notice` VALUES ('', '$ Row [id]', 0, NOW (), '$ p2') "); } ?>

and I have server time displayed, -4 hours for me. If I register NOW () -> ‘$ date’ together, then the date is displayed in the database as 0000-00-00 00:00:00. I can not understand why this is so? In separate files such as chat and registration, the function $ date is also registered and in the SQL query it is ‘$ date’ instead of NOW () and everything displays correctly. Why does index.php not work?

Blockquote

Try CURRENT_TIMESTAMP()

Also -4 hours as NOW ();
In the database, I have the value DATETIME, but I set the TIMESTAMP and it’s still -4 hours

You cannot change the default timezone for the database, sadly :slight_smile:
Better use PHP command:

date("Y-m-d H:i:s");

I’m use
date_default_timezone_set (‘Europe / Samara’);
$date = date(“Y-m-d H:i:s”);
and

mysqli_query($CONNECT, "INSERT INTO `notice` VALUES ('', '$Row[id]', 0, date, '$p2')"); 

but time 00000, if write $date or ‘$date’ The database does not receive requests

So try

echo $date;

ate_default_timezone_set (‘Europe / Samara’);
echo $date;

function SendNotice($p1, $p2) {
global $CONNECT;
$Row = mysqli_fetch_assoc(mysqli_query($CONNECT, “SELECT id FROM users WHERE login = ‘$p1’”));
if (!$Row[‘id’]) echo ‘Error’;
mysqli_query($CONNECT, “INSERT INTO notice VALUES (’’, ‘$Row[id]’, 0, ‘$date’, ‘$p2’)”);
}
date is displayed as 00000000

That’s weird, can you try echoing date(“Y”);

date_default_timezone_set (‘Europe / Samara’);
$ date = date (“Y-m-d G: i: s”);
works if I am on any page of my site, such as profile, login, news. On these pages, the date is displayed correctly. But in the file I’m trying to write the date, it’s not a public page that you can go to. This is a page with all the functionality, the pages that I connect to the site, connecting the database. This file is a single entry point.

What is your website please?

1 Like

https://vkr2018.000webhostapp.com/