<body>
<div><font size=4 color=blue face="黑體"><p align=center>計算壹元二次方程的解</font></div>
<div><font size=4 face="黑體" color=red><p align=center>aX*X+bX+c=0</font></div>
<form action="" method="post">
<table border="1" align="center" cellpadding="0" cellspacing="0">
<tr><td colspan="2" align="center" bgColor="#999999">表單</td></tr>
<tr><td>系數a:</td><td><input name="a" type="text"></td></tr>
<tr><td>系數b:</td><td><input name="b" type="text"></td></tr>
<tr><td>系數c:</td><td><input name="c" type="text"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" name="submit" value="提交">
<input type="reset" name="submit2" value="重置"></td></tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];
$resu2=$b*$b-4*$a*$c;
if($resu2>=0)
{
$x1=(-$b+sqrt($resu2))/(2*$a);
$x2=(-$b-sqrt($resu2))/(2*$a);
echo"<script>alert('輸入的數為:a=".$a.",b=".$b.",c=".$c.";所以方程的解為:x1=".$x1.",x2=".$x2."');</script>";
}
else
{
echo"<script>alert('方程無解!');</script>";
}
}
>