Hi all,
First of all - I tried searching for an alternate thread about my dilemma, but couldn't fine one so I'm posting a new one.
I have a user editing page contained by one form, where values are fetched from an SQL table. Imagine it like this:
<form name="userlist" action="" method="post">
<table>
<tr>
<td>username</td><td>level</td></td>active</td>
</tr>
<tr>
<td>foobar</td>
<td>
<input type="hidden" name="userid" value="99" />
<select name="userlevel">
<option value="10">10: inactive </option>
<option value="20" selected>20: beginner </option>
<option value="30">30: admin </option>
</select>
</td>
<td>
<select name="useractive">
<option value="yes" selected>yes</option>
<option value="no">no</option>
</select>
</td>
</tr>
<tr>
(.......here are a few more users......)
</tr>
<tr><td><input type="submit" name="submitedit" value="submit" /></td></tr>
</table>
</form>
Now, as listed are, say, five(5) users with everyone having a different value in userlevel or useractive. I want to change for example one of the users' values with one form, in stead of having to create a separate editing page for each user. So far if I go about getting field values with $_POST, I only get the values of the last user, like so:
$id = $_POST[ "userid" ];
$level = $_POST[ "userlevel" ];
$active = $_POST[ "useractive" ];
$sql = "UPDATE users SET userlevel='$level',active='$active' WHERE id='$id'";
$db->Query( $sql ); // Only the last user is changed when I run this
So in essence I would need to find out which users have had their properties changed and then run a single SQL query to update all. Is this possible, and if, how ? Or do I need to run a query for each user separately?
I'm thankful for any old pointers!