Help - Search - Members - Calendar
Full Version: [resolved] Date is always January 01 1970
Codegrrl.com Forums > Script Help > Tutorial Help
Vlad
The problem is that every new post is added with one date - January 01 1970 sad.gif
CODE
<? $page_title = 'Летопись школы';
include('header.php');
session_start();
if (!$_SESSION[login]) {
echo "Нужно <a href='login.php'>Войти</a>";
include ('footer.php');
} else
{ include ('connection.php');
setlocale (LC_ALL, 'ru_RU.CP1251');
$month = strftime('%B');
$date = strftime('%d');
$year = strftime('%G');
$time = strftime('%H:%I');
?>
<center>
<div id="contenido">
<form method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<select name="month" id="month">
<option value="<?php echo $month; ?>"><?php echo $month; ?></option>
<option value="Январь">Январь</option>
...
</select><input type="text" name="date" id="date" value="<? echo $date; ?>">
<select name="year" "year">
<option value="<?php echo $year; ?>"><? echo $year; ?></option>
<option value="2004">2004</option>
...
</select>
<input type="text" name="time" id="time" value="<? echo $time; ?>"><br><br>Введите название вехи:<br>
<input type="text" name="title" id="title" size="40" /><br><br>
Вехо:<br>
<textarea cols="80" rows="20" name="entry" id="entry"></textarea>
<input type="submit" name="submit" id="submit" value="Отправить вехо" />
</form><a href="menu.php">Вернуться к меню</a><br><a href="editinglist.php">Редактировать летопись</a></div></center>
<?
if (isset($_POST['submit'])) {
$month = htmlspecialchars(strip_tags($_POST['month']));
$date = htmlspecialchars(strip_tags($_POST['date']));
$year = htmlspecialchars(strip_tags($_POST['year']));
$time = htmlspecialchars(strip_tags($_POST['time']));
$title = htmlspecialchars(strip_tags($_POST['title']));
$entry = $_POST['entry'];
$realtime = strtotime($month."".$date."".$year."".$time);
$entry = nl2br($entry);
if (!get_magic_quotes_gpc()) {
$title = addslashes($title);
$entry = addslashes($entry);
}
$sql = "INSERT INTO chronic (time, title, entry) VALUES ('$realtime', '$title', '$entry')";
$result = mysql_query($sql) or print('Заклинанния барохлят.<br />.'.$sql.' <br />'. mysql_error());

    if ($result != false) {
        print "<center>Вы успешно добавили событие.</center>";
    }

    mysql_close();
}
include('footer.php');
}
?>
echolalia
I'll take a stab at this. I had a similar problem some time ago -- my timestamps weren't created properly before being inserted into the database. (My server was showing the date as December 31 1969, though.)

Could this line be the cause?
CODE
$time = strftime('%H:%I');

I looked up strftime in the PHP manual; %H & %I are different ways of displaying the hour, so maybe the timestamps are getting mangled for you as well.
Try this:
CODE
$time = strftime('%H:%M');

Replacing the %I with %M might work. If that fails, hopefully someone else with better eyes than mine will be able to figure out what's up! wink.gif
Vlad
Thanx smile.gif Fiexed
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.