簡體   English   中英

HTML選擇表單,POST沒有值

[英]Html select form, no value with POST

我遇到了問題,我花了很多時間試圖解決它,但找不到解決方案。

所以我得到了這個HTML表單:

<form method="post" action="register.php" name="registerform">

<label for="signup_game_name">Game Name</label> <br>
<select id="signup_game_name" class="reg_input" size="1" name"game_id" required>

<option value="2">Game1</option>
<option value="3">Game2</option>

</select>
<br><br>



<label for="signup_input_teamname">Team name </label> <br>
<input id="signup_input_teamname" class="reg_input" type="text"  name="team_name" required /> 
<br><br>


<input type="submit"  name="register" value="Signup" /> </form>

我使用php類(函數)為選擇表單生成“選項”(我剛剛在上面發布了該函數的結果)。 它的簡單功能:從GET方法中獲取值,並使用它從數據庫中獲取值並為選擇表單創建“選項”。

單擊表單上的提交按鈕后,我可以在班級中使用$_POST['team_name'] ,但$_POST['game_id']不可用(其為空)。 我收到錯誤消息: Notice: Undefined index: game_id

我知道我想念一些東西,但找不到。

這是<select>標記中名稱和“ game_id”之間的=符號:

<select id="signup_game_name" class="reg_input" size="1" name="game_id" required>

您缺少=

<select id="signup_game_name" class="reg_input" size="1" name"game_id" required>

應該

<select id="signup_game_name" class="reg_input" size="1" name="game_id" required>

另一件事...在您的問題中,您提到了一個使用GET檢索數據的函數,但是您在表單中使用POST 可能也想檢查一下。

您忘記在“名稱”中添加等號:

NAME = “game_id”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM