Take data from form, process and return to the same form
I am aware I have no vailidation or sanitziation. This will be added :D
I currently have a php form which requests the following information:
- Avg. salary
- number of employees
- Pension Uptake PCT
- Pension Contributuin PCT
Which is then submitted, and proccessed by a file called SSESC.php (code will be below).
It should then return, the computed data to the field Total Employee contribution ($TEC
) and Total Savings ($NISAVING
)
I can get the data passed to the SSEC.php file, and it is processed (tested by echo) but I am unable to get the data back and displayed on the form.
Im attempting to save the data into a session, and then return and refill the form. Im returning from the script by using <?php header ("location: form.php");?>
. this works but the form is not filled in. I will include the snippets below from the form.
SSESC.php code
<?php header ("location: form.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SSEC-Process</title>
</head>
<?php
setlocale(LC_MONETARY, 'en_GB');
$Average_Salary = $_POST["Average_Salary"];
$EMPNUM = $_POST["EMPNUM"];
$PUPCT = $_POST["PUPCT"];
$PCPCT = $_POST["PCPCT"];
$TEC = "";
$NI_save = "";
$employeepension = $PCPCT/100;
$pensionuptake = $PUPCT/100;
$TEC = $Average_Salary*$employeepension*$EMPNUM*$pensionuptake;
$combi = $TEC*13.8/100;
$NI_save = money_format('%.0i', $combi);
$_SESSION["TEC"] = money_format('%.0i',$TEC);
$_SESSION["NISAVE"] = $NI_save;
?>
<body>
</body>
</html>
Form Snippets
<input id="TEC" name="TEC" class="Label" type="text" maxlength="255" value="<?= $_SESSION['TEC']?>"/>
<input id="NI_save" name="NI_save" class="label" type="text" maxlength="255" value="<?=$_SESSION['NISAVE开发者_运维问答']?>"/>
Thanks in advance. Steve.
- You are not starting the session handler. You should have
session_start();
on top of both of your scripts. (Both in this script and in form.php. Right at the top) - Why are you outputting HTML if you are not showing any, and redirecting to another file anyways?
- Remove the unnecessary HTML on the processing script, and move the
header()
call to the bottom of the processing script.
I will suggest to write the standard tag (<?php echo
) because the short-end tag is not always enabled. So you have to write:
value="<?php echo $_SESSION['TEC']?>"
Have you called session_start
before this statements?
Try this first and after do a var_dump
to test if the value has been setted right.
Try modifying your form with:
<input id="TEC" name="TEC" class="Label" type="text" maxlength="255" value="<?php echo $_SESSION['TEC']?>"/>
<input id="NI_save" name="NI_save" class="label" type="text" maxlength="255" value="<?php echo $_SESSION['NISAVE']?>"/>
精彩评论