我正在更新一个 mysql 表。我收到如下错误
警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在 C:\xampp\htdocs\test\edit.php 第 232 行错误中给出。您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '' 附近使用正确的语法
该查询似乎没有产生结果。我正在通过 url 将 id 传递给函数,但变量似乎已死,尽管它似乎在范围内。什么可能是我的错误。更新循环如下。我已经注释掉了一些我认为有问题的行,但它们很好。粗体代码是问题行。
elseif(isset($_POST['editSelection']))
{
// check if form is submitted
//collect variables posted by form.
$fixture_id = mysql_real_escape_string($_POST['fixture_id']);
$goalkeeper = mysql_real_escape_string($_POST['goalkeeper']);
$defender = mysql_real_escape_string($_POST['defender']);
$fullback = mysql_real_escape_string($_POST['fullback']);
$midfielder = mysql_real_escape_string($_POST['midfielder']);
$wing = mysql_real_escape_string($_POST['wing']);
$striker = mysql_real_escape_string($_POST['striker']);
$sid = mysql_real_escape_string($_POST['sid']); // receive the selection_id which was posted from the hidden field in the editForm
$sql = "SELECT * FROM `selections` WHERE selection_id = {$sid}";
$data = mysql_query($sql);
**while($rows = mysql_fetch_array($data))
{
$opponents = $rows['opponents'];
}**
//validate form by checking for empty strings that user might have submitted using strlen() php built-in method. If no empty string form processes
//if(strlen($fixture_id)>0 && strlen($goalkeeper)>0 && strlen($defender)>0 && strlen($fullback)>0 && strlen($midfielder)>0 && strlen($wing)>0 && strlen($striker)>0 && strlen($selection_id)>0) { // if form fields are not empty, update Selection record in database
$sql = "UPDATE `selections` SET goalkeeper ='{$goalkeeper}' WHERE selection_id = {$sid}";
$query = mysql_query($sql) or die("Error executing query ".mysql_error());
echo "Selection updated <br/><br/>";
echo "<a href=\"team_selections.php\">Go back to Team Selections page </a>";
//}
}
echo"<tr><td>Midfielder</td><td><select name=\"midfielder\">";
$sql = "SELECT name FROM `player` ";
$data = mysql_query($sql);
while($rows = mysql_fetch_array($data)){
echo "<option value={$rows['name']}>";
echo $rows['name'];
echo "</option>";
}
echo "</select>";
echo "</td></tr>";
echo"<tr><td>Wing</td><td><select name=\"wing\">";
$sql = "SELECT name FROM `player` ";
$data = mysql_query($sql);
while($rows = mysql_fetch_array($data)){
echo "<option value={$rows['name']}>";
echo $rows['name'];
echo "</option>";
}
echo "</select>";
echo "</td></tr>";
echo"<tr><td>Striker</td><td><select name=\"striker\">";
$sql = "SELECT name FROM `player` ";
$data = mysql_query($sql);
while($rows = mysql_fetch_array($data)){
echo "<option value={$rows['name']}>";
echo $rows['name'];
echo "</option>";
}
echo "</select>";
echo "</td></tr>";
echo "<tr><td></td><td><input type=\"hidden\" value=\"{$rows['selection_id']}\" name=\"sid\"></td></tr>"; // create hidden field with selection_id which enables the right selection to be edited
echo "<tr><td></td><td><input type=\"submit\" value=\"Update Selection\" name=\"editSelection\"></td></tr>";
echo "</table></form>";
} //end of while loop
}