PHP Level = beginner
我正在尝试编写一个显示特定次数的简单程序 放入输入框时的值。我试图使用post方法来执行此操作,但每次程序运行并选择提交按钮时,它会显示php文件'timescalc.php'的完整代码。我想知道我做错了什么,虽然我知道 if语句的计算可能是错误的。
继承代码
<DOCTYPE html>
<html>
<head>
<title>Number Times</title>
</head>
<body>
<h1>Number Times Table Calculator</h1>
<form method="post" action="timescalc.php">
Enter Number : <input type="text" name="number"> <br>
<input type="submit" value="submit"/>
</form>
<?php
$number = $_POST['number'];
if ($number == 2, $number ++2)
{
echo $number . ;
}
else if ($number == 3, $number ++3)
{
echo $number . ;
}
else if ($number == 4, $number ++4)
{
echo $number . ;
}
else if ($number == 5, $number ++5)
{
echo $number . ;
}
else
{
echo "pick numbers from 2 to 5 only" ;
}
?>
</body>
</html>
答案 0 :(得分:0)
您的php
代码中存在大量语法错误,但在此处进行了更正,您还需要像WAMP SERVER这样的网络服务器来运行php代码。祝你好运!
<DOCTYPE html>
<html>
<head>
<title>Number Times</title>
</head>
<body>
<h1>Number Times Table Calculator</h1>
<form method="post" action="test.php">
Enter Number : <input type="text" name="number"> <br>
<input type="submit" value="submit"/>
</form>
<?php
$number = $_POST['number'];
if ($number == 2)
{
$number = $number * 2;
echo $number ."." ;
}
else if ($number == 3)
{
$number = $number * 3;
echo $number ."." ;
}
else if ($number == 4)
{
$number = $number * 4;
echo $number ."." ;
}
else if ($number == 5)
{
$number = $number * 5
echo $number ."." ;
}
else
{
echo "pick numbers from 2 to 5 only" ;
}
?>
</body>
</html>