我只在用户输入整数值(no
字符串、浮点数等)时才尝试打印表格,但是这段代码不起作用让我现在缺少什么来获取整数值而不JAVASCRIPT
在前端使用。如果我错过了一些逻辑,请告诉我。
这是我的 php 代码 ( index.php ) --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>table Data</title>
</head>
<body>
<table width="29%" border="1">
<form name="mytableform" id="mytableform" action="mytabledata.php" method="POST">
<tr>
<td width="42%">Enter any munber : </td>
<td width="58%"><input type="text" name="mynumber" id="mynumber" /> </td>
</tr>
<tr>
<td>Enter limit : </td>
<td><input name="limit" type="text" id="limit" /> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" name="submit" /> </td>
</tr>
</form>
</table>
</body>
</html>
我的mytabledata.php内容文件——
<?php
$number = $_POST['mynumber'];
$limit = $_POST['limit'];
//var_dump($number);
//var_dump($limit);
if( is_int($number) )
{
for($i=1;$i<=$limit;$i++)
{
$p= $number * $i;
echo $number." X ".$i." = "." ".$p.";";
echo "<br />";
}
}
else{
echo "Please check the type of data you are entering.";
}