To update a specific user you will need to pass the user id within in the form (I did it here with a textbox but you can also use the hidden input if you don’t want/need it seen)
To confirm that you are updating the correct user I would leave the input as visible where is shows the user id and then echo out after the update to make sure it was id=‘2’ and not ‘22’ or whatever.
the form action=’’ is where you keep the script that will handle the query. You’ll notice here that it is left blank because it is on the same page ( right at the top with the if(isset($_POST[‘updateUser’])) )
[php]<?php
// This begins the update user query
if(isset($_POST[‘updateUser’])){
$id = $_POST[‘user_id’]; // passed through from the form
$userLevel = $_POST[‘users_level’]; // passed through from the form
// Your mysql query to update the user level....change what is necessary to make it work
$update = mysql_query("UPDATE tblName SET users_level='$userLevel' WHERE user_id='$id'");
// if the query was successful...
if($update){
echo "
Successfully updated user: $id to level: $userLevel
";
}
// query was not successful
else {
echo "Error: ".mysql_error();
}
} // End the user level update query
// This is the start of your code
$con = mysql_connect(“HOST”,“NAME”,“PASS”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“DBNAME”, $con);
$result = mysql_query(“SELECT * FROM TBLNAME”);
echo "
User ID |
Username |
First Name |
Last Name |
Email |
User Level |
Change User Level |
";
while($row = mysql_fetch_array($result))
{
echo “
”;
echo “” . $row[‘IDS’] . “ | ”;
echo “” . $row[‘usersname’] . “ | ”;
echo “” . $row[‘firstname’] . “ | ”;
echo “” . $row[‘lastname’] . “ | ”;
echo “” . $row[‘useremail’] . “ | ”;
echo “” . $row[‘users_level’] . “ | ”;
//BELOW IS MY DROPBOX
//Unsure of how to correctly run a new MYSQL query
//with the selected option from dropbox
//to update table with NEW selected option
echo “
”;
// I edited here
// action=’’ means script is located in this same file
// added a text input field to pass the user id…to hide this change the attribute type=‘text’ to type=‘hidden’
echo "
<input type=‘text’ size=‘3’ name=‘user_id’ value=’".$row[‘IDS’]."’/>
// user levels
“.$row[‘users_level’].”
User
Co-Admin
Admin
";
echo “
| ”;
echo “
”;
}
echo “
”;
mysql_close($con);
?>[/php]
Please take the time to thoroughly go through this and try to understand what is going on in it.
If you do have questions please ask and also let us know of any error messages.