我有一张表格,可以打印出我表格中的所有用户。每个用户旁边是一个选择框和一个更新按钮。我遇到的问题是脚本只从最后一个选择框读取。如何使选择框动态化,以便脚本知道选择框来自哪一行?
选择框代码:
<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' ");