I'm trying to get this script in php to work but it doesn't want to:
<body>
<FORM ACTION="second.php" METHOD="post">
YourName:
<INPUT TYPE="text" NAME="YourName"><BR />
CostOfLunch:
<INPUT TYPE="text" NAME="CostOfLunch"><BR />
DaysBuyingLunch:
<INPUT TYPE="text" NAME="DaysBuyingLunch"><BR />
<INPUT TYPE="submit" NAME="x" VALUE="Calculate">
</FORM>
</body>
And the second file.
<body>
<?php $Today = date("l F d. Y"); ?>
Today's Date:
<?php
/*
** show today's date
*/
print("<H3>$Today</H3>");
/*
** show information about cost of lunch
*/
print("$YourName, this week, you will spend ");
print($CostOfLunch * $DaysBuyingLunch);
print(" dollars for lunch.<BR />
");
?>
</body>
I'm testing these files in two ways:
- By running
php -S 0.0.0.0:8000 first.php
this command in cmd. And then navigating to adress bar in browser. I'm typing therehttp://localhost:8000/
. In this way the page doesn't output thesecond.php
but shows first page and clears the forms. It changes tohttp://localhost:8000/second.php
though. - By typing
http://localhost:portnumber/first.php
in the adress bar. This works somewhat better cause I have installed the Appache HTTP Server. It navigates tohttp://localhost:port/second.php
and changes the output of the site to the content of a file. Alas like this:Today's Date: , this week, you will spend 0 dollars for lunch.
without running any script.
EDIT: Changing script to use echo and $_POST
instead of print()
like this <?php echo $_POST['yourName']; ?>
have worked.
But only when using APACHE. When using built-in web server site content is not changing just clearing.