Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just installed AppServ 8.6 I cannot get the program to run. I am certain I have all the brackets, etc. but all it does is regurgitates the code put into it. What am I missing? This program should post upon itself from the post method after executing a Javascript Program "..."

PHP
<?php
	$mo = filter_input(INPUT_POST, "mo");
	$dy = filter_input(INPUT_POST, "dy");
	$yr = filter_input(INPUT_POST, "yr");
	$hr = filter_input(INPUT_POST, "hr");
	$mn = filter_input(INPUT_POST, "mn");
	$sc = filter_input(INPUT_POST, "sc");
		
	session_start();
		$_SESSION['mo'] = $mo;
		$_SESSION['dy'] = $dy;
		$_SESSION['yr'] = $yr;
		$_SESSION['hr'] = $hr;
		$_SESSION['mn'] = $mn;
		$_SESSION['sc'] = $sc;
		$_SESSION['count'] = $count;
	session_write_close();	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="EN" dir="ltr" xmin="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
    <title>Title.php</title>
     ...
</head>
<body>
     <form id="myform" method="Post" action="Title.php">
         <center><table><tr>
             <td align="center"><input type="text" name="mo" value="<?php echo $_SESSION['mo']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="dy" value="<?php echo $_SESSION['dy']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="yr" value="<?php echo $_SESSION['yr']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="hr" value="<?php echo $_SESSION['hr']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="mn" value="<?php echo $_SESSION['mn']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="sc" value="<?php echo $_SESSION['sc']; ?>" size="4"/></td>
          </tr</table></center>
    </form>
</body>
</html>


What I have tried:

I have made certain there are no extra brackets, close quotes, etc.
Posted
Updated 7-Mar-17 17:40pm

1 solution

There are couple of things

1. You need to comment out $_SESSION['count'] = $count; because $count variable is no way to be found
2. move the session_start(); to the top
3. wrap the code with if (isset($_POST['validate'])) { so that the session variable will not be overwritten on page load
4. maybe you didn't post complete code, there is no submit button on the form.

Here how the code should look like.
PHP
<?php
session_start();
if (isset($_POST['validate'])) {
	$mo = filter_input(INPUT_POST, "mo");
	$dy = filter_input(INPUT_POST, "dy");
	$yr = filter_input(INPUT_POST, "yr");
	$hr = filter_input(INPUT_POST, "hr");
	$mn = filter_input(INPUT_POST, "mn");
	$sc = filter_input(INPUT_POST, "sc");
		
	//session_start();
		$_SESSION['mo'] = $mo;
		$_SESSION['dy'] = $dy;
		$_SESSION['yr'] = $yr;
		$_SESSION['hr'] = $hr;
		$_SESSION['mn'] = $mn;
		$_SESSION['sc'] = $sc;
		//$_SESSION['count'] = $count;
	session_write_close();	
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="EN" dir="ltr" xmin="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
    <title>Title.php</title>
     ...
</head>
<body>
     <form id="myform" method="Post" action="">
         <center><table><tr>
             <td align="center"><input type="text" name="mo" value="<?php echo $_SESSION['mo']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="dy" value="<?php echo $_SESSION['dy']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="yr" value="<?php echo $_SESSION['yr']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="hr" value="<?php echo $_SESSION['hr']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="mn" value="<?php echo $_SESSION['mn']; ?>" size="4"/></td>
             <td align="center"><input type="text" name="sc" value="<?php echo $_SESSION['sc']; ?>" size="4"/></td>
          </tr</table></center>
    </form>
	<input type='submit' name="validate" id="validate" value='Submit' />
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900