I'm connecting to a MySQL database and retrieving information that will populate some HTML form drop down boxes. The problem is my boxes are being populated with PHP code instead of the correct information. My server info is all correct (it has been cleared in the code below) but I'm not sure what I'm doing wrong here. If anyone could point me in the right direction that would be greatly appreciated.
<html>
<head>
<title>Assignment 11</title>
</head>
<body>
<?php
//Connect to MySQL
$servername = "";
$username = "";
$password = "";
$dbname = "";
//Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
//Check connection
if ($conn) {
echo "Connected successfully";
}
echo "Connected successfully";
//Variables
$txtFirstName = $_POST["txtFirstName"];
$txtLastName = $_POST["txtLastName"];
$txtAddress = $_POST["txtAddress"];
$txtCity = $_POST["txtCity"];
$txtZip = $_POST["txtZip"];
$Genders = mysqli_query($conn, "SELECT GenderID, Gender FROM TGenders");
$States = mysqli_query($conn, "SELECT StateID, State FROM TStates");
$ShirtSize = mysqli_query($conn, "SELECT ShirtSizeID, ShirtSize FROM TShirtSizes");
?>
<table width = "300", border="1">
<form name="frmGolfers" method="post" action="process_golfers.php">
<colgroup>
<col width="35%"></col>
<col width="65%"></col>
</colgroup>
<tr>
<td colspan="2">Golfers</td>
</tr>
<tr>
<td><label for="selState">State: </label></td>
<td><select name="selState" required>
<option value="">Select State</option>
<?php
if (mysqli_num_rows($States) > 0) {
while($row = mysqli_fetch_assoc($States)) {
echo "<option value ='".$row["StateID"]."'>" .$row["State"]. "</option>";
}
} else {
echo "0 results";
}
?>
</select></td>
</tr>
<tr>
<td><label for="selShirtSize">Shirt Size: </label></td>
<td><select name="selShirtSize" required>
<option value="">Select Shirt Size</option>
<?php
if (mysqli_num_rows($ShirtSize) > 0) {
while($row = mysqli_fetch_assoc($ShirtSize)) {
echo "<option value ='".$row["ShirtSizeID"]."'>" .$row["ShirtSize"]. "</option>";
}
} else {
echo "0 results";
}
?>
</select></td>
</tr>
<tr>
<td><label for="selGender">Gender: </label></td>
<td><select name="selGender" required>
<option value="">Select Gender</option>
<?php
if (mysqli_num_rows($Gender) > 0) {
while($row = mysqli_fetch_assoc($Gender)) {
echo "<option value ='".$row["GenderID"]."'>" .$row["Gender"]. "</option>";
}
} else {
echo "0 results";
}
?>
</select></td>
</tr>
</form>
</table>
</body>
<?php
// Close connection
mysqli_close($conn);
?>
</html>