0

I'm having a problem with an undefined index error message in PHP. I have a form with several <select> inputs, and all of them work except for one. On one I get the undefined index error message. I don't understand why this is happening, as it is formatted exactly the same as the other <select> inputs. I've made sure that the $_POST assignment in the attached script is referencing the correct element name, and that the option values are correct in the HTML.

The code for the entire form is here: https://pastebin.com/52xtECCT

Here is the code for the <select> element:

        <td>Team to Represent:</td>
        <td><select name="txtTeamType" id="txtTeamType">
        <?php
            $resultSet = $conn->query("SELECT intTypeofTeamID, strTypeofTeam FROM TTypeofTeams");
            while ($rows = $resultSet->fetch_assoc())
            {
                $intTypeofTeamID = $rows['intTypeofTeamID'];
                $strTypeofTeam = $rows['strTypeofTeam'];
                echo "<option value='$intTypeofTeamID'>$strTypeofTeam</option>";
            }
            ?>
        </select>
        </td>
    </tr>

And here is the code for the variable assignment. This is the code that throws the error: $intTypeofTeamID = $_POST["txtTeamType"];

Thanks for any help, I really appreciate it.

Martin
  • 22,212
  • 11
  • 70
  • 132
Ethan Malloy
  • 555
  • 1
  • 4
  • 16
  • use `print_r($rows);` for each while loop to see what is returning – Jasar Orion Nov 16 '20 at 20:07
  • 2
    The code you say is causing the error is not in the code block you've posted. Include the bad code __in the question__ –  Nov 16 '20 at 20:30

1 Answers1

0

I found the solution. Changing $intTypeofTeamID = $_POST["txtTeamType"]; to

if (isset($_POST["txtTeamType"])) { $intTypeofTeamID = $_POST["txtTeamType"]; } fixed the issue.

Ethan Malloy
  • 555
  • 1
  • 4
  • 16