テーブルからすべてのユーザーを出力するテーブルがあります。各ユーザーの横には、選択ボックスと更新ボタンがあります。私が抱えている問題は、スクリプトが最後の選択ボックスからのみ読み取ることです。選択ボックスを動的にして、選択ボックスがどの行からのものであるかをスクリプトが認識できるようにするにはどうすればよいですか?
選択ボックスのコード:
<select name="level" >
<option value="basic" SELECTED>Basic</option>
<option value="premium">Premium</option>
<option value="platinum">Platinum</option>
</select>
<button type="submit" name="update" value="<?php echo $row['id'] ?>">Update</button>
送信ボタンが押されたときに有効になる別のスクリプトのコード:
if ( isset( $_POST['update'] ) ) {
//Get the ID of the account that will be updated
$userID = $_POST['update'];
//Get the level that the admin wishes to change to
$level= $_POST['level'];
//Connect to the DB
mysql_connect("localhost", "xxxx", "xxxx")or die("Cannot connect to database");
mysql_select_db("xxxx")or die("Database cannot be selected or it doesnt exist");
//Updates the users access level
mysql_query("UPDATE users SET level='$level' WHERE id='$userID' ");