我的表单有问题,我正在显示数据库中的两行,它们使用相同的表单(使用 while 循环)将值放回数据库。问题在于显示的第二行或底行有效很好,但是例如,如果我单击底部的值 1,则顶部的一个有效,只有当我单击值 1 并且之后停止工作时,顶部的一个才有效。
我的网站是www.albsocial.us/test/seria.php自己检查一下,我在这种情况下包含了一个视频http://www.youtube.com/watch?v=xGwPd_P65oM
<?php
session_start();
include("connect.php");
$query = "SELECT * FROM test ORDER BY `id` ASC LIMIT 2";
$result = mysql_query($query);
echo "<h2>Seria A</h2><hr/>";
while($row = mysql_fetch_array($result)){
$id = $row['id'];
$home = $row['home'];
$away = $row['away'];
$win = $row['win'];
$draw = $row['draw'];
$lose = $row['lose'];
echo "<br/>",$id,") " ,$home, " - ", $away;
echo "
<form action='seria.php' method='post' id='$id'>
<select name='test'>
<option value=\"\">Parashiko</option>
<option value='1'>1</option>
<option value='X'>X</option>
<option value='2'>2</option>
<input type='submit' name='submit' value='Submit'/>
<input type='hidden' name='id' readonly value='".$row['id']."'/>
</select>
<br/>
</form>";
echo "Totali ", $sum = $win+$lose+$draw, "<br/><hr/>";
}
if (!empty($_POST)) {
$id=isset($_POST['id'])&&is_numeric($_POST['id']) ? $_POST['id']:false;
$select = isset($_POST['test']) ? $_POST['test']:false;
switch ($select) {
case 1:
$select = $win + $select;
mysql_query("UPDATE test SET win='$select' WHERE id='$id'");
break;
case 'X':
$select = '1';
$select = $draw + $select;
mysql_query("UPDATE test SET draw='$select' WHERE id='$id'");
break;
case 2:
$select = '1';
$select = $lose + $select;
mysql_query("UPDATE test SET lose='$select' WHERE id='$id'");
break;
default:
}
header('Location: ../test/seria.php');
}
?>