私はPHPが初めてで、一日中この問題に苦労しています。プレイヤーの詳細を含む MySQL データベースがあります。データベースからそれらを選択し、フォームのテーブルに表示したいのですが、これは以下のコードでうまく機能します。
問題は、オプション フィールドを使用してプレーヤーのステータスをアクティブから非アクティブに変更するために、行を更新したいときに発生します。送信を押すと、各 pdbactive フィールドの値を取得できますが、データベースへの更新を行うためのキーである PID を取得できません。
<form name="selected_players" action="" method="POST">
<table border="1">
<th>Player ID</th>
<th>Player Name</th>
<th>Player Surname</th>
<th>Status</th>
<th>Primary Team*</th>
<?php
// Then get the players from the players table who have got same team_name but no team_id yet....which would have be set if they were active
$query = "select * from `player2012` where teamid ='$tid' and aru='A';";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$count = mysql_num_rows($result);
echo $count;
//echo ("<br />");
while ($row = mysql_fetch_assoc($result)) {
$player_id = $row["player_id"];
$player_fname = $row["player_fname"];
$player_sname = $row["player_sname"];
$pactive = $row["active"];
//echo ($pactive);
//echo ("<br />");
?>
<tr>
<td><input name"pid[]" id="pid[]" type="text" value="<?php echo $player_id ?>" /><?php echo $player_id ?></td>
<td><input name"player_fn[]" type="hidden" value="<?php echo $player_fname ?>" /><?php echo $player_fname ?></td>
<td><input name"player_sn[]" type="hidden" value="<?php echo $player_sname ?>" /><?php echo $player_sname ?></td>
<?php if($pactive=="1"){
?>
<td><select name="pdbactive[]" id="pdbactive[]">
<option value="1" selected="selected">Active</option>
<option value="0">Not Active</option>
</td>
<?php }
else
{
?>
<td><select name="pdbactive[]" id="pdbactive[]">
<option value="1">Active</option>
<option value="0" selected="selected">Not Active</option>
</td>
<?php
}
?>
<td>
</td>
</tr>
<?php
}
?>
</table>
<p> </p>
<p> When you have updated "status" for each of these players, please press submit button
<input name="Submit" type="submit" id="Sumbit" value="Submit" /> </p>
</form>
<?php
mysql_free_result($result);
//if form has been pressed proccess it
if($_POST["Submit"])
{
//get data from form
$ractive = $_POST['pdbactive'];
$rid= $_POST['pid'];
for($i=0;$i<$count;$i++){
echo ($i);
echo ("<br />");
$stat=($ractive[$i]);
$idd=($rid[$i]);
$sql_insert="UPDATE 'player2012' SET active='$stat' where id='$idd'";
print($sql_insert);
echo ("<br />");
}
}
?>
現時点では、SQL ステートメントを作成したいだけなので、データベースの更新を開始する前に機能することがわかります。だから、すべてのエコーとプリントは、私が答えを見つけようとしているだけです
ヘルプ!!!!!!!!!!!!!!