Jump to content

Recommended Posts

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">&nbsp;&nbsp;
<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>";
?>

Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/
Share on other sites

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 by StevenOliver
Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1578989
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1579012
Share on other sites

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 by dodgeitorelse3
Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1579031
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1579036
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1579071
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1579074
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/310958-server-problem/#findComment-1579310
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.