unrelenting
08-10-2008, 07:04 PM
$_POST['date'] equals a date and time in this format: 9/6/08 6:00 pm
If I just do this it converts properly to a timestamp:
$timestamped = strtotime("9/6/08 6:00 pm");
But if it is passed along in a form it doesn't work for me anymore. Like this:
$game_time = $_POST['date'];
$timestamped = strtotime($game_time);
We just changed servers so I can't help but wonder if that may be the problem because I'm pretty sure it worked fine before but I haven't used this script in many months.
CFMaBiSmAd
08-10-2008, 07:09 PM
Have you echoed $_POST['date'] to see what it actually contains and please define: "it doesn't work for me anymore". Telling or showing what you see in front of you would help someone determine what exactly is going wrong.
unrelenting
08-10-2008, 07:17 PM
Have you echoed $_POST['date'] to see what it actually contains and please define: "it doesn't work for me anymore". Telling or showing what you see in front of you would help someone determine what exactly is going wrong.
Yes, I can echo out the $game_time variable. But when I echo out the $timestamped variable it doesn't contain anything at all.
I even added this to see the results that follow:
$game_time = $_POST['date'];
$timestamped = strtotime($game_time);
$timestamped2 = strtotime("9/6/08 6:00 pm");
echo 'game_time is ' . $game_time . '<br />';
echo 'timestamped is ' . $timestamped . '<br />';
echo 'timestamped2 is ' . $timestamped2 . '';
game_time is 9/6/08 6:00 pm
timestamped is
timestamped2 is 1220742000
CFMaBiSmAd
08-10-2008, 07:27 PM
I would guess that the POST variable contains some non-printing characters. Add the following two lines immediately after your first opening <?php tag -
ini_set ("display_errors", "1");
error_reporting(E_ALL);Use var_dump() to see more about what the variable contains -
var_dump($_POST['date']);And can you post the form so that someone could try to duplicate the results.
Edit: Another possibility is that $timestamped corresponds to a post/get/cookie/session variable due to register_globals. Change the variable name to something else as a test.
unrelenting
08-10-2008, 07:50 PM
I would guess that the POST variable contains some non-printing characters. Add the following two lines immediately after your first opening <?php tag -
ini_set ("display_errors", "1");
error_reporting(E_ALL);Use var_dump() to see more about what the variable contains -
var_dump($_POST['date']);And can you post the form so that someone could try to duplicate the results.
Edit: Another possibility is that $timestamped corresponds to a post/get/cookie/session variable due to register_globals. Change the variable name to something else as a test.
No errors reported.
The var_dump printed this:
string(15) "9/6/08 6:00 pm"
I changed the name to $timestamped3 and same result.
The file is database driven so I stripped it down to the basics to test and it gives the same problem. I have also run this on a separate server and gotten the same result.
<html>
<head>
<title>Edit the Football Schedule</title>
</head>
<body>
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
$game_time = $_POST['date'];
$timestamped3 = strtotime($game_time);
$timestamped2 = strtotime("9/6/08 6:00 pm");
echo 'game_time is ' . $game_time . '<br />';
echo 'timestamped is ' . $timestamped3 . '<br />';
echo 'timestamped2 is ' . $timestamped2 . '';
var_dump($_POST['date']);
}
$new_date = "9/6/08";
$new_time = "6:00 pm";
echo '
<center><br /><font size="9" color="#cc0000"><b>Edit Football Schedule</b></font><br />
<table border="1" width="75%" cellpadding="3">
<tr>
<td><center><b>Date/Time</b></center></td>
<td><center><b>Edit</b></center></td>
</tr>
<form action="' .$_SERVER['PHP_SELF']. '" method="post">
<tr>
<td align="center"><input type="text" size="15" name="date" value="' . $new_date . ' ' . $new_time . '" /></td>
<td align="center"><input type="submit" name="submit" value="Edit" /></td>
</tr>
</form>
</table>
</center>';
?>
</body>
</html>
CFMaBiSmAd
08-10-2008, 08:18 PM
The problem is the non-breaking space between the date and time in the form value. I tried using html_entity_decode(), but that did not change anything. The only thing I can think that is probably at fault is the default page encoding that the web server is using. You could try putting in a specific character set encoding in the head of the document.
I recommend just using a literal space character instead of in this case.
unrelenting
08-10-2008, 08:30 PM
The problem is the non-breaking space between the date and time in the form value. I tried using html_entity_decode(), but that did not change anything. The only thing I can think that is probably at fault is the default page encoding that the web server is using. You could try putting in a specific character set encoding in the head of the document.
I recommend just using a literal space character instead of in this case.
Genius!
I removed that non-breaking space symbol and it prints correctly now. Awesome. Thanks.
CFMaBiSmAd
08-10-2008, 08:32 PM
I played around with this some more and it appears this is an IE browser problem (possibly combined with the page character encoding.) It works with in FF.
unrelenting
08-10-2008, 09:00 PM
I played around with this some more and it appears this is an IE browser problem (possibly combined with the page character encoding.) It works with in FF.
It must be a character encoding issue then. I had some character encoding issues with my data displaying on the new server but I thought it was just the way it dumped. I used a different script to dump and upload and the character problems went away. I dunno.
I was using FF the whole time and it never did work for me so that may enhance your suggestion that it's a character encoding issue.
I'm just glad to be done with it. :thumbsup: