charlie321 Posted June 18, 2020 Share Posted June 18, 2020 Hi... I have a little form and php script where I am trying to pass date() and get the seconds it takes to fill out the form. This works fine on localhost which is window based, but does not work on my server which is linux. On my linux server a 0 or blank is showing in the passed field. Any ideas on what might be wrong? I believe tjis is some sort of a minor coding error but my server shows no errors. Here is the script: <html> <form method="POST" action="test_time.php"> <input type="hidden" name="tm" value="<?php echo time() ?>" /> <input type="text" name="Name" size="15" placeholder="Enter Name"> <input type="submit" value="Go" name="Submit"> </form> </html> <?php date_default_timezone_set("America/New_York"); $name = ucwords(strtolower($_POST['Name'])); $st = $_POST['tm']; $formFilledInSeconds = time() - $st; echo $name."<br>"; echo "start time: ".$st."<br>"; echo "time: ".time()."<br>"; echo "seconds: " .$formFilledInSeconds."<br>"; ?> Quote Link to comment Share on other sites More sharing options...
StevenOliver Posted June 18, 2020 Share Posted June 18, 2020 (edited) you forgot the colon after echo time() While coding in PHP, having the following lines on top of all your PHP pages will save a ton of time. (Be sure to remove them before making your pages live to the public.): <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ?> Edited June 18, 2020 by StevenOliver Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 18, 2020 Author Share Posted June 18, 2020 colon??? What are you talking about? Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 19, 2020 Author Share Posted June 19, 2020 17 hours ago, StevenOliver said: you forgot the colon after echo time() While coding in PHP, having the following lines on top of all your PHP pages will save a ton of time. (Be sure to remove them before making your pages live to the public.): <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ?> Could you please explain further? I think you were mistaken. But if you are certain you are correct about the colon please explain in detail. Quote Link to comment Share on other sites More sharing options...
Barand Posted June 19, 2020 Share Posted June 19, 2020 @StevenOliver The final ";" before a "?>" is optional; the end of statement is implied. Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 19, 2020 Author Share Posted June 19, 2020 7 hours ago, Barand said: @StevenOliver The final ";" before a "?>" is optional; the end of statement is implied. You are talking about a semi-colon not colon? You are talking about the php script? What specific line are you talking about? Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 20, 2020 Author Share Posted June 20, 2020 13 hours ago, Barand said: @StevenOliver The final ";" before a "?>" is optional; the end of statement is implied. OK I think I understand. You threw me off by calling the semi-colon a colon. Unfortunately that did not solve the problem. Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted June 20, 2020 Share Posted June 20, 2020 (edited) I don't know what code is in test_time.php so I get an error that that page is not found. When I remove the form action page and leave it blank it seems to work for me and it seems to be starting the time when page loads. This was tested on my linux server. Edited June 20, 2020 by dodgeitorelse3 Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 20, 2020 Author Share Posted June 20, 2020 OK I have no idea why but I changed the html file to a php file and echoed the form. It actually works now on both the localhost and server. time() just would not pass from my html localhost script. I would love to know why. It might have something to do with the fact that my localhost is workbench and the server is mariadb. Or the server could be a newer version of php. Really appreciate the help and suggestions. Quote Link to comment Share on other sites More sharing options...
Barand Posted June 20, 2020 Share Posted June 20, 2020 Are you now telling us that the php code that wasn't working was in a .html file and not in a .php file? Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted June 21, 2020 Share Posted June 21, 2020 I am guessing OP's original post had the html part of code in an .html file and the php code was what he had in his form action file Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 22, 2020 Author Share Posted June 22, 2020 On 6/20/2020 at 5:53 PM, Barand said: Are you now telling us that the php code that wasn't working was in a .html file and not in a .php file? No.. Actually I have been saying that from the beginning of this thread. If I tried to pass this from the html file to the php file it passed nothing or 0. That was on my mariadb server. If I passed it on my localhost workbench server it worked. When I changed the html file to a php file ie test.php it worked on both servers. Like I said I'd love to know why even though I did find a work around. The original html and php scripts for this is in the original thread above. Quote Link to comment Share on other sites More sharing options...
StevenOliver Posted June 23, 2020 Share Posted June 23, 2020 Okay, I meant semicolon.... @charlie321, no, it was not mentioned that your file was an actual ".html" file (file with suffix .html). A server's PHP interpreter will only parse PHP if it is ".php" file (file ending with .php suffix). In the olden days, I stupidly had a server directive whereby php would parse both .php files AND .html files. Stupid stupid stupid. Never never never do this. Anyway, your code shows the input was hidden, so you probably wouldn't have seen it just casually looking at your web browser, but if you would have looked in the source code, you would probably have seen the words "<?php echo....." all spelled out :-) Barand, thank you -- I didn't know you could leave the semicolon off the last line. I don't think I would make a habit of it, though.... I'm so used to semicolons. Quote Link to comment Share on other sites More sharing options...
Barand Posted June 23, 2020 Share Posted June 23, 2020 I too prefer always to have the ";" at the statement ends in the main code but I don't bother with it when I use something like <?= $username ?> Quote Link to comment Share on other sites More sharing options...
charlie321 Posted June 30, 2020 Author Share Posted June 30, 2020 On 6/22/2020 at 11:21 PM, StevenOliver said: Okay, I meant semicolon.... @charlie321, no, it was not mentioned that your file was an actual ".html" file (file with suffix .html). A server's PHP interpreter will only parse PHP if it is ".php" file (file ending with .php suffix). In the olden days, I stupidly had a server directive whereby php would parse both .php files AND .html files. Stupid stupid stupid. Never never never do this. Anyway, your code shows the input was hidden, so you probably wouldn't have seen it just casually looking at your web browser, but if you would have looked in the source code, you would probably have seen the words "<?php echo....." all spelled out :-) Barand, thank you -- I didn't know you could leave the semicolon off the last line. I don't think I would make a habit of it, though.... I'm so used to semicolons. OK It does parse an html file on my localhost server. So what changed the ability to parse an html file? Linux, php, windows? Just curious to find out why I can do it on localhost (workbench-windows) and not on linux-mariadb. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.