I had a problem with undefined warning messages but that is solved now.
The only problem I have is that once I input the time it does not convert it into the time on the selected time zone.
When I click the button to process the form it displays the results page but the time does not change.
The time is the same on the current time zone and on the selected time zone.
This is the form:
Code: Select all
<html>
<head>
<title>Time Zone Converter</title>
</head><body>
<?php
// An array holds the standard time zone strings
$time_zones = array(
"Asia/Hong_Kong",
"Africa/Cairo",
"Europe/Paris",
"Europe/Madrid",
"Europe/London",
"Asia/Tokyo",
"America/New_York",
"America/Los_Angeles",
"America/Chicago");
// Check to see if the form has been submitted
if (isset($_GET['start_time'])) {
$start_time_input = $_GET['start_time'];
$start_tz = $_GET['start_tz'];
$end_tz = $_GET['end_tz'];
putenv('TZ = $start_tz');
$start_time = strtotime($start_time_input);
echo "<p><strong>";
echo date("h:i:sA",$start_time)."\n";
echo "</strong>";
putenv('TZ=$end_tz');
echo "in $start_tz becomes ";
echo "<strong> ";
echo date("h:i:sA",$start_time)."\n";
echo "</strong>";
echo " in $end_tz.</p><hr />";
} else {
$start_time_input = '';
$start_tz = '';
$end_tz = '';
}
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="GET">
<label>
Your Time:
<input type="text" name="start_time" value="<?php echo $start_time_input; ?>">
</label> in
<select name="start_tz">
<?php
foreach ($time_zones as $tz) {
echo '<option';
if (strcmp($tz, $start_tz) == 0) {
echo ' selected="selected"';
}
echo ">$tz</option>";
}
?>
</select>
<p>Convert to:
<select name="end_tz">
<?php
foreach ($time_zones as $tz) {
echo '<option';
if (strcmp($tz, $end_tz) == 0) {
echo ' selected="selected"';
}
echo ">$tz</option>";
}
?>
</select>
<input type="submit" value="Convert!">
</form>
</body>
</html>I would appreciate any help in guiding me to the best way to figure out how to fix this problem.
It seems that the book I trusted will give some tools to learn PHP is not that good (Learning PHP and MySQl, Oreilly 1st Ed). So, if anybody has an suggestion on a great book for beginners PHP programmers I'll appreciate a title or two.
Thanks,