'字段列表'中的未知列'xxxxxx'

时间:2015-08-10 18:48:50

标签: php mysql

我知道有很多这方面的主题,我看了他们所有,他们没有帮助我。我的表名是正确的,没有空格或任何不寻常的东西。我已经检查了100次并检查了100次。我会发布我的代码的两个部分,希望有人可以提供帮助。

当我尝试使用提交按钮时出现此错误: 更新赔率时出错:“字段列表”中的未知列'homeOdds'

POST:

if ($_POST['action'] == 'Update') {
foreach($_POST['game'] as $game) {

    $homeScore = ((strlen($game['homeScore']) > 0) ? $game['homeScore'] : 'NULL');
    $homeOdds = (str_replace("\xBD", ".5", $homeScore));
    $visitorScore = ((strlen($game['visitorScore']) > 0) ? $game['visitorScore'] : 'NULL');
    $visitorOdds = (str_replace("\xBD", ".5", $visitorScore));
    $sql = "update " . $db_prefix . "schedule ";
    $sql .= "set homeOdds = '" . $homeOdds . "', visitorOdds = '" . $visitorOdds . "' ";
    $sql .= "where gameID = " . $game['gameID'];
    mysql_query($sql) or die('Error updating odds: ' . mysql_error());
}
header('Location: index.php');
}

表格/表格&更新按钮:

<form id="scoresForm" name="scoresForm" action="odds.php" method="post">
<input type="hidden" name="week" value="<?php echo $week; ?>" />
<?php
$sql = "select s.*, ht.city, ht.team, ht.displayName, vt.city, vt.team, vt.displayName ";
$sql .= "from " . $db_prefix . "schedule s ";
$sql .= "inner join " . $db_prefix . "teams ht on s.homeID = ht.teamID ";
$sql .= "inner join " . $db_prefix . "teams vt on s.visitorID = vt.teamID ";
$sql .= "where weekNum = " . $week . " ";
$sql .= "order by gameTimeEastern";
$query = mysql_query($sql);
if (mysql_num_rows($query) > 0) {
echo '<table cellpadding="4" cellspacing="0" class="table1">' . "\n";
echo '  <tr><th colspan="6" align="left">Week ' . $week . '</th></tr>' . "\n";
$i = 0;
while ($result = mysql_fetch_array($query)) {
    $homeTeam = new team($result['homeID']);
    $visitorTeam = new team($result['visitorID']);
    $rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
    echo '      <tr' . $rowclass . '>' . "\n";
    echo '          <td><input type="hidden" name="game[' . $result['gameID'] . '][gameID]" value="' . $result['gameID'] . '" />' . date('D n/j g:i a', strtotime($result['gameTimeEastern'])) . ' ET</td>' . "\n";
    echo '          <td align="right"><input type="hidden" name="gameID[' . strtolower($visitorTeam->team) . ']" value="' . $result['gameID'] . '" />' . $visitorTeam->teamName . '</td>' . "\n";
    echo '          <td><input type="text" name="game[' . $result['gameID'] . '][visitorScore]" id="game[' . $result['gameID'] . '][visitorScore]" value="' . $result['visitorOdds'] . '" size="3" /></td>' . "\n";
    echo '          <td align="right"><input type="hidden" name="gameID[' . strtolower($homeTeam->team) . ']" value="' . $result['gameID'] . '" />at ' . $homeTeam->teamName . '</td>' . "\n";
    echo '          <td><input type="text" name="game[' . $result['gameID'] . '][homeScore]" id="game[' . $result['gameID'] . '][homeScore]" value="' . $result['homeOdds'] . '" size="3" /></td>' . "\n";
    echo '      </tr>' . "\n";
    $i++;
}
echo '</table>' . "\n";
}
?>
<br><input type="submit" name="action" value="Update" />
</form>

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

为了调试它,在将$sql变量提交给数据库之前,回显(或var_dump)动态生成的SQL。

然后将该语句带到另一个客户端进行测试。

MySQL告诉您,您引用的表schedule不包含名为homeOdds的列。

我们没有看到所有变量的内容被合并到SQL文本中。 (该代码似乎容易受到SQL注入攻击。