<body>
<form id= "form1" name="assignment5" action= "assignment.php" method="POST">
<div class="elements">
<label>Company Name:</label>
<input type="text" name="cname" placeholder="Company Name"/>
</div>
<div class="elements">
<label>Owner:</label>
<input type="text" name="owner" placeholder="Owner"/>
</div>
<div class="elements">
<label>Address:</label>
<input type="text" name="address" placeholder="Address"/>
</div>
<div class="elements">
<label>Phone Number:</label>
<input type="text" name="number" placeholder="Phone Number"/>
</div>
<div class="elements">
<label>Annual Sales:</label>
<input type="number" name="annualsales"/>
</div>
<div class="elements">
<label>Borrow Amount: </label>
<input type="number" name="borrowamount"/>
</div>
<div class="elements">
<label>Payment Terms: </label>
<input type="number" name="paymentterms"/>
</div>
<br>
<input type="reset" value="Reset Fields"/>
<input type="submit">
</form>
<br>
</body>
<body>
<?php
$companyname=$_POST['cname'];
$annualsales=$_POST['annualsales'];
$borrowamount=$_POST['borrowamount'];
$paymentterms=$_POST['paymentterms'];
$interest=($borrowamount*($paymentterms/12))*0.03;
$payment = $borrowamount+ $interest;
$profit = $payment-$borrow;
?>
<table>
<tr>
<th> Company name </th>
<th> Annual Sales </th>
<th> Borrow Amount </th>
<th> Payment Terms </th>
<th> Total Interest </th>
<th> Total Payment </th>
<th> Profit </th>
</tr>
<tr>
<td> <?php echo "$_POST['cname']" ?> </td>
<td> <?php echo "$annualsales" ?> </td>
<td> <?php echo "$borrowamount" ?> </td>
<td> <?php echo "$paymentterms" ?> </td>
<td> <?php echo "$interest" ?> </td>
<td> <?php echo "$payment" ?> </td>
<td> <?php echo "$profit" ?> </td>
</tr>
</table>
为什么不这样做?
它需要输出在表单中接收的输入,位于.php文件中创建的表中的正确位置。截至目前,它不会输出应该输出变量内容的任何内容。
答案 0 :(得分:0)
您的代码中存在一些问题
以action
不正确的形式出现
action="assignment5.php";
有几个问题
您在其中分配变量$profit
,它应该如下所示
$profit = $payment-$borrow;
您回显帖子变量$_POST['cname']
的行应该如下所示
<td> <?php echo $_POST['cname'] ?> </td>
这里的问题是它不会将'cname'传递给数组并给出一个未终止的空格错误。
否则我已经测试了这段代码并且有效。