简单的php / html计算页面问题

时间:2016-04-23 09:22:07

标签: php html

我一直在努力为最后一小时设置一个简单的gps转换页面。它基本上有两个数字的输入,然后应该计算,结果应该回显。由于某种原因,它不会工作。这就是我得到的:

<html> 

<body>




<form action="#" method="post">
Grad: <input type="text" name="search1" placeholder=" grad ... "/>
Min: <input type="text" name="search2" placeholder=" min ... "/>
<input type="submit" value="Submit" /><input type="hidden" name="doSearch" value="1">
</form>

<?php 
if($_POST['doSearch']==1) {
$grad = (int)$_POST['search1'];
$min = (int)$_POST['search2'];
$kord = ($min / 60) + $grad;
return $kord;

}
?>




</body> 
</html>

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

只需将PHP脚本放在上面,声明$ kord变量,然后在html中显示。

<?php 
$kord = 0;
if($_POST['doSearch']==1) {
$grad = (int)$_POST['search1'];
$min = (int)$_POST['search2'];
$kord = ($min / 60) + $grad;
}
?>

<html> 


<body>
<form action="#" method="post">
Grad: <input type="text" name="search1" placeholder=" grad ... "/>
Min: <input type="text" name="search2" placeholder=" min ... "/>
<input type="submit" value="Submit" />
<input type="hidden" name="doSearch" value="1">
<?php if(isset($kord)) echo "Result:".$kord; ?>
</form>
</body> 
</html>