【发布时间】:2016-04-14 02:31:01
【问题描述】:
这是一个使用 php 变量和解析的计算器。我在 url 中为变量输入的内容与在表单中输入它们的内容相同。当我点击提交时,它应该计算。但是不知道哪里错(没有正确分配变量?)非常感谢!
这是我的问题: 1。我应该在哪里修复它才能正确计算? 2.如何通过在表单中输入来更改页面的实际表格填充和表格边框? 3. 如何使用从 URL 传递的变量更改表格的背景颜色?
<?php
// parse variables from URLs
echo "This is the value of <b>x:</b> " . $_GET['x'] . ". This is the value of <b>y: </b> " . $_GET['y'] . ".This is the value of <b>z: </b> " . $_GET['z'] . " , And the title is: " . $_GET['title'] . ".";
?>
<?
$result1 = $x + $y - 2*$z;
$result2 = 2*$x + 4*$y + (3*$z - 80);
$result3 = $result1 + $result2;
?>
<center><h2> Math </h2></center>
<center>
<table cellpadding=20 border=20 bgcolor=#00ffff >
<tr>
<td><b>Mathematical Operation</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td>x + y - 2 * z</td>
<td><?echo "$result1";?></td>
</tr>
<tr>
<td>2x - 4y + (3z - 80)</td>
<td><?echo "$result2";?></td>
</tr>
<tr>
<td>Row2 - Col2 + result of Row3 - Col2</td>
<td><?echo "$result3";?></td>
</tr>
</table>
</center>
<form>
<u>Inputs:</u> <br />
X-value <input type="text" name="x" value=""></input><br />
Y-Value <input type="text" name="y" value=""></input><br />
Z-Value <input type="text" name="z" value=""></input><br />
Title <input type="text" name="title" value=""></input><br />
Table Padding <input type="text" name="pad" value=""></input><br />
Table Border <input type="text" name="brdr" value=""></input><br />
Background Color <input type="color" name="bckrd" value=""></input><br />
<input type="submit" name="submit" value="SUBMIT and CALCULATE"></input>
</form>
<?
if ($_GET['submit']) {
$result1 = $x + $y - 2*$z;
$result2 = 2*$x + 4*$y + (3*$z - 80);
$result3 = $result1 + $result2;
}
?>
【问题讨论】:
标签: php parsing variables calculator