Php html数字输入文件

Php html数字输入文件,php,html,wordpress,Php,Html,Wordpress,我有以下代码: <!DOCTYPE html> <html> <body> <form action="<?=$PHP_SELF?>" method="post"> <table style="width:100%"> <tr> <td> <form><input type=number min="0"

我有以下代码:

<!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模板中运行它,它会导致这个问题,还是其他原因?

因为您在所有文本输入之前和之后打开和关闭表单

试试这个:

<!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>

  • 您不能为每个
  • 此外,为了便于配音,请将
    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>