我有以下代码:
<!DOCTYPE html>
<html>
<body>
<form action="<?=$PHP_SELF?>" method="post">
<table style="width:100%">
<tr>
<td>
<form><input type=number min="0" max="19" name="score1" /></form>
</td>
<td>
<form><input type=number min="0" max="19" name="score2" /></form>
</td>
</tr>
</table>
<?php
global $score1;
global $score2;
echo "Score 1= " . $_POST['score1']. " ";
echo "Score 2= " . $_POST['score2']. " ";
?>
<input type="submit"/>
</form>
</body>
</html>
score1正确显示,但score2始终为空。我在wordpress模板中运行它,它可能导致这个问题,还是别的什么?
答案 0 :(得分:1)
因为您在所有文本输入之前和之后打开和关闭表单。
试试这个:
<!DOCTYPE html>
<html>
<body>
<form action="<?=$PHP_SELF?>" method="post">
<table style="width:100%">
<tr>
<td><input type=number min="0" max="19" name="score1" />
</td>
<td>
<input type=number min="0" max="19" name="score2" />
</td>
</tr>
</table>
<?php
global $score1;
global $score2;
echo "Score 1= " . $_POST['score1']. " ";
echo "Score 2= " . $_POST['score2']. " ";
?>
<input type="submit"/>
</form>
</body>
</html>
答案 1 :(得分:1)
<td>
PHP
代码放在顶部,然后html
个文件以下更改
<table style="width:100%">
<tr>
<td><form> <input type=number min="0" max="19" name="score1" />
</form>
</td>
<td><form> <input type=number min="0" max="19" name="score2" />
</form>
</td>
</tr>
</table>
到
<?php
global $score1;
global $score2;
echo "Score 1= " . $_POST['score1']. " ";
echo "Score 2= " . $_POST['score2']. " ";
?>
<form action="<?=$PHP_SELF?>" method="post">
<table style="width:100%">
<tr>
<td><input type=number min="0" max="19" name="score1" /></td>
<td><input type=number min="0" max="19" name="score2" /></td>
</tr>
</table>
<input type="submit"/>
</form>