在表格内过帐表格

时间:2018-12-04 09:24:26

标签: php mysql

我在表格中有一张桌子。大多数字段通过循环从数据库中的数据填充。但是,我还有两个输入字段,用户可以在其中输入一些结果,然后提交表单。提交后,应使用这些结果更新数据库。

当我加载页面时,该表将显示所有数据。但是,在表格上方,我在第37行的C:\ xampp \ htdocs \ testsite \ test-predictions.php中收到一条错误消息“注意:未定义的索引:(输入框显示在此处而不是表格中!!)它显示十次,这是两个字段乘以生成的行数的代码。

<?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

有人可以告诉我如何解决吗?我还是PHP的初学者。谢谢。

2 个答案:

答案 0 :(得分:3)

存在问题的行是这样的:

<td>". $row["<input type='text' name='homescore'/>"] ."</td>

将其更改为:

<td><input type='text' name='homescore'/></td>

只是一些语法上的混淆。

答案 1 :(得分:0)

您正在尝试访问索引:

  

input type ='文本'name ='homescore'

     

input type ='text'name ='awayscore'

未定义