I have a table within a form. Most of the fields are populated by data from the database via a loop. But then I have two input fields as well where the user will input some results, and then submit the form. On submission, the database should be updated with these results.
When I load the page, the table appears with all the data. However, above the table I am getting an error message "Notice: Undefined index:(the input box is shown here and not in the table!!) in C:\xampp\htdocs\testsite\test-predictions.php on line 37. It shows ten times, which is the two fields times the number of rows generated. This is the code:
<?php
include 'includes/dbh.inc.php';
?>
<div class="predictions_container">
<form class="predictions" name="predictions" action="test-predictions.php" method="post">
<table class="table">
<thead>
<tr class="active">
<th>Match ID</th>
<th>Match Date</th>
<th>Locked</th>
<th>Home Team</th>
<th>Home Score</th>
<th>Home Score</th>
<th>Away Score</th>
</tr>
</thead>
<?php
// Get data to fill table columns
$sql = "SELECT match_id, matchdate, locked, hometeam, awayteam from matches";
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr class='info'>
<td>". $row["match_id"] ."</td>
<td>". $row["matchdate"] ."</td>
<td>". $row["locked"] ."</td>
<td>". $row["hometeam"] ."</td>
<td>". $row["awayteam"] ."</td>
<td>". $row["<input type='text' name='homescore'/>"] ."</td>
<td>". $row["<input type='text' name='awayscore'/>"] ."</td>
</tr>";
}
} else {
echo "No results";
}
$conn-> close();
?>
</table>
<td><input class="submit" type="submit" size="30" value="Submit" /></td>
</form>
</div>
<?php
Can someone please tell me how I can fix it? I'm still quite a beginner in PHP. Thanks.