0

I am not able to get this program working. I'm sure I have all the correct syntax, brackets etc... However, it just spits out code that is put into it, am I missing anything?

The program should post upon itself from the post method, after executing a JavaScript program.

<!DOCTYPE HTML>
<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>Site.php</title>
    </head>
    <body>
        <form id="myform" method="Post" action="Site.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>

<?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();
?>
4
  • Do you mean that it just outputs the actual PHP code? If so, perhaps PHP isn't installed on the server, or the server isn't set to invoke PHP for .php files. Commented Mar 12, 2017 at 12:42
  • Is your PHP code before the HTML? Commented Mar 12, 2017 at 12:42
  • put php code before form Commented Mar 12, 2017 at 12:43
  • how do you submit your form ? without at least submit button ? how do you expect that the data will be submitted without submission ? Commented Mar 12, 2017 at 12:47

1 Answer 1

1

1 . Take your session_start() to the top of your page.

2 . validate your count variable as it doesn't exists.. may be you are loading it from somewhere else, do this isset($count) ? $count : "";

3 . Add a submit button to your form in order to store data in your session.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.