表单中的选项输入未通过

Option input in form not passing

我正在尝试使用表格来填写我的数据库。我使用数据库中的 table 来填写表单中的选项并且它有效,但是值没有被传递,我 运行 通过我的代码并且找不到拼写错误,是吗我没有看到错误?

<?php
require("db.php");
?>
<html>
   <head>
      <title>Insert a Record in MySQL Database</title>
   </head>

   <body>
      <?php
         if(isset($_POST['insert']))
         {            
            $user_added = $_POST['user_added']; 
            $age_added = $_POST['age_added'];

            $insert_query = "INSERT INTO userList ";
            $insert_query .= "(user, Age) ";
            $insert_query .= "VALUES ";
            $insert_query .= "('$user_added', '$age_added')";

            $retval = mysqli_query($connection, $insert_query);

            if(!$retval )
            {
                 die ("The error is: " . mysqli_error($connection));
            }
            else
            {
            echo "Database Updated " . $age_added . " " . $user_added;
            }
         }
         else
         {
            ?>
               <form method="post" action="<?php $_PHP_SELF ?>">
                  <table width="400" border="0" cellspacing="1" cellpadding="2">
                     <tr>
                        <td width="100">User to Add</td>
                        <td><input name="user_added" type="text" id="user_added"></td>
                     </tr>
                     <tr>
                        <td width="100">Age</td>
                        <td><select name="age_added" id="age_added">
                        <?php
                            while ($selection = mysqli_fetch_assoc($age_query))
                            {
                                echo "<option value=\"{$selection['id']}\">{$selection['age']}</option>\n";
                            }
                            ?>
                            </select>
                        </td>
                     </tr>
                     <tr>
                        <td width="100"> </td>
                        <td>
                           <input name="insert" type="submit" id="insert" value="Insert">
                        </td>
                     </tr>                  
                  </table>
               </form>
            <?php
         }
      ?>
   </body>
</html>
<?php
    mysqli_close($connection);
?>

如果我在用户中输入 Test 并在年龄中输入 select 数字,则输出不会发送年龄,并且显示 Database Updated Test 没有年龄。我错过了什么?

----- 添加信息 1 -----

这是根据请求创建 $age_query 的查询

<?php
//Perfom DB query
$query = "SELECT * FROM PermittedAges ";
$query .= "ORDER BY Age asc";
$age_query = mysqli_query($connection, $query);

//Test for query error
if (!$age_query) {
    die ("Database query failed.");
}
?>

但我不确定这是怎么回事,因为它只填充下拉字段中的选项并且它有效

----- 添加信息 2 -----

这是var_dump($_POST)输出

array(3) { ["user_added"]=> string(4) "Test" ["Age_added"]=> string(0) "" ["insert"]=> string(6) "Insert" }

试试这个

<?php
      while ($selection = mysqli_fetch_assoc($age_query))
      {
?>
      <option value="<? echo $selection['id']; ?>"> <? echo $selection['age']; ?> </option>
<?
      }
?>

@Alex 谢谢。我意识到我的错误在于我的语法。该值未被传递,我将其从

更改为

echo "<option value=\"{$selection['id']}\">{$selection['age']}</option>\n";

echo "<option value=\"{$selection['age']}\">{$selection['age']}</option>\n";