bookincome.php接受几个输入,bi.php根据bookincome.php的值计算总净收入,并显示一个表格,其中包含用户的所有给定值和计算的总账面收入( $ tnibeforetax)价值。现在我在report1.php中有一个表,我想在其中显示计算的$ tnibeforetax值,我无法在report1.php中显示该表中的值。请帮忙
bookincome.php的代码:
<?php
// start session
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title> Book Income </title>
</head>
<body>
<center>
<h2>BOOK INCOME AS PER TRIAL BALANCE ENTRY </h3>
</center>
<form name='form' action="bi.php" method='post' autocomplete='off' target="_blank" [....]>
<table cellspacing="10">
<tr>
<br>
<td align="left">Book Income as per Trial Balance: </td>
<td><input type="number" name="bi" value="<?php if(isset($_POST['bi'])) ?>"></td>
</tr>
<tr>
<br>
<td align="left">Late Adjustment 1: </td>
<td><input type="number" name="la1" value="<?php if(isset($_POST['la1'])) ?>"></td>
</tr>
<tr>
<br>
<td align="left">Late Adjustment 2: </td>
<td><input type="number" name="la2" value="<?php if(isset($_POST['la2'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Late Adjustment 3: </td>
<td><input type="number" name="la3" value="<?php if(isset($_POST['la3'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Audit Adjustment 1: </td>
<td><input type="number" name="aa1" value="<?php if(isset($_POST['aa1'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Audit Adjustment 2: </td>
<td><input type="number" name="aa2" value="<?php if(isset($_POST['aa2'])) ?>"><br> </td>
</tr>
<tr>
<br>
<td align="left">Audit Adjustment 3: </td>
<td><input type="number" name="aa3" value="<?php if(isset($_POST['aa4'])) ?>"><br> </td>
</tr>
</table>
<br>
<center> <button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button> </center>
</form>
</body>
</html>
&#13;
以下是bi.php的代码:
<?php
// start session
session_start();
$bi = $_POST['bi'];
$la1 = $_POST['la1'];
$la2 = $_POST['la2'];
$la3 = $_POST['la3'];
$aa1 = $_POST['aa1'];
$aa2 = $_POST['aa2'];
$aa3 = $_POST['aa3'];
$tnibeforetax= $bi + $la1 + $la2 + $la3 + $aa1 + $aa2 + $aa3;
$_SESSION['tnibeforetax'] = $tnibeforetax;
?>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:50%" align="center">
<tr>
<td width="70%"> </td>
<td align="center"> Amount </td>
</tr>
<tr>
<td> Book Income as per trail Balance </td>
<td align="right">
<?php echo $bi ; ?> </td>
</tr>
<?php
if($la1!=0)
{
echo '<tr><td> Late Adjustment1 </td> ';
echo '<td align="right">'. $la1 . '</td><tr>';
}
?>
<?php
if($la2!=0)
{
echo '<tr><td> Late Adjustment2 </td>';
echo '<td align="right">'. $la2 . '</td></tr>';
}
?>
<?php
if($la3!=0)
{
echo '<tr><td> Late Adjustment3 </td> ';
echo '<td align="right">'. $la3 . '</td></tr>';
}
?>
<?php
if($aa1!=0)
{
echo '<tr><td> Audit Adjustment1 </td> ';
echo '<td align="right">'. $aa1 . '</td></tr>';
}
?>
<?php
if($aa2!=0)
{
echo '<tr><td> Audit Adjustment2 </td></tr> ';
echo '<tr><td align="right">'. $aa2 . '</td></tr>';
}
?>
<?php
if($aa3!=0)
{
echo '<tr><td> Audit Adjustment3 </td>';
echo '<td align="right">'. $aa3 . '</td></tr>';
}
?>
<tr>
<td> Total Net Income before tax as per Income Statement </td>
<td align="right">
<?php echo $tnibeforetax ; ?> </td>
</tr>
&#13;
report1.php的代码:
<?php
// start session
session_start();
$tnibeforetax = $_SESSION['$tnibeforetax'];
?>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td
{
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:50%" align="center" >
<tr>
<td style="font-weight:bold" colspan="2" ><font color="darkgreen" > Income from Business & Proffession:</td></font>
</tr>
<tr>
<td> Net Income before tax as per Income Statement </td>
<td width="25%"> <?php echo "$" . $tnibeforetax; ?></td>
</tr>
&#13;
答案 0 :(得分:0)
您只是checking
而不是checking and printing
所以在此更改以及
<td><input type="number" name="bi" value="<?php $_POST['bi'] ?? '' ?>"></td>
此处$_POST['bi'] ?? ''
与php 7中的isset($_POST['bi']) ? $_POST['bi'] : ''
相同。
为bi.php
$bi = $_POST['bi'] ?? 0;
答案 1 :(得分:0)
$tnibeforetax = $_SESSION['$tnibeforetax'];
值内没有$
。
答案 2 :(得分:0)
它无法正常工作的原因是因为您将会话设置为值tnibeforetax
但是使用$tnibeforetax
设置,请替换第3个文件中的上述代码,即report1.php
。
<?php
// start session
session_start();
$tnibeforetax = $_SESSION['tnibeforetax'];
?>
答案 3 :(得分:0)
您忘记在value
属性中添加结果的输出。
<td><input type="number" name="bi" value="<?php $_POST['bi'] ?? '' ?>"></td>
到
<td><input type="number" name="bi" value="<?php echo isset($_POST['bi']) ? $_POST['bi'] : '' ?>"></td>
la1
,la2
等等。
在php.ini文件中使用short_open_tag=On
,它可以只是<?= isset($_POST['bi']) ? $_POST['bi'] : '' ?>
。在PHP 7中,它可以只是<?= $_POST['bi'] ?? '' ?>
。
$tnibeforetax = $_SESSION['$tnibeforetax'];
必须是
$tnibeforetax = $_SESSION['tnibeforetax'];
请为变量使用更易理解的名称。变量的名称必须尽可能清楚地匹配存储在其中的数据。例如,而不是bi
使用bookIncome
。
答案 4 :(得分:0)