尝试更新 MySQL 表但没有更新,我确定我只是没有看到这个小问题,希望得到一些帮助。谢谢
所以它是一个曲棍球池的交易区,如果你想让球员在交易区,那么你只需检查表格中的 CHECKBOX 并提交,它应该将数据库中的值更改为“1”。
形式:
echo "<table border='1'>";
echo "<tr><th>NAME</th> <th>POS</th> <th>BLOCK</th></tr>";
$counter = 1;
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo "{$row['f_name']}" . " " . "{$row['l_name']}";
echo "</td><td><input name='pl_id[$counter]' type='hidden' value='{$row['pl_id']}'>";
echo "{$row['pos']}";
echo "</td><td><input name='pos[$counter]' type='hidden' value='{$row['pos']}'>";
echo "<input type='checkbox' name='block[$counter]' size='1' value='1'";
if($row['block'] == '1')
{
echo "checked='checked'";
}
echo "></td></tr>";
$counter++;
}
echo "</table>";
提交 PHP 页面:
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("mbbcom1_fantrax") or die(mysql_error());
$i = 1;
while ($i < 26) {
$block = $_POST['block'][$i];
$pl_id = $_POST['pl_id'][$i];
$query = mysql_query("UPDATE 'players'
SET `block` = '$block'
WHERE `players`.`pl_id` = '$pl_id'");
mysql_query($query);
$i++; }
echo mysql_close();