Jump to content

Using php variable in html select input forms name


firehawk777

Recommended Posts

So as to why its hard to explain but here goes.

I am basically embedding one form inside another.

First I call an array of users from the database and make a list that displays on the page.

I have a check box for each user for deleting the user in the list that is posted to an array.

Now I want to also have the option to be able to change the users level from the same list so I want to use the variable $user (username) as the name of each select input then check if that username is posted and update the level of the user from that.

 

If you still don't understand heres the complete code minus some of the css

function ViewUsers($theaction)
{
$query = "SELECT * FROM users";
$result=mysql_query($query) or die("Invalid Query : ".mysql_error());
$row=mysql_fetch_array($result);
$num=mysql_numrows($result); 
echo"<div class='post'>";
if ($num > 0){
echo "<h2>Users: $num</h2>";
}else{
echo "<h2>Users: No Users</h2>";
}

if(!mysql_num_rows($result)) 
        die("No users found.");   
$i=0;
echo"<ul>";
echo"<form name='levelform' method='post' action='$theaction'>";
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$user=mysql_result($result,$i,"user");
$email=mysql_result($result,$i,"email");
$rquery = "SELECT * FROM profiles WHERE pid='$id'";
$rresult=mysql_query($rquery) or die("Invalid Query : ".mysql_error());
$level=mysql_result($rresult,0,"level");

echo"<li>";
echo"<table border='0' width ='500'>";
echo"<tr>";
echo"<td width='100'>";
echo"<div id='meta' STYLE='color: #FF0000;'> User</div> </td><td  STYLE='color: #FF0000;'>$user";
echo"</td></tr>";
echo"<tr><td>";
echo"<div id='meta'>Email</div> </td><td>$email";
echo"</td>";
echo"</tr><tr><td>";
echo "<input type='checkbox' value='$id' name='userdelete[]' />"; 
echo "Delete:</td><td>$user";
echo"</td></tr>";
echo"<tr><td>";

echo"<select name='";
echo"$user";
echo"'>";
if ($level == 1){
echo"<option value='1' selected='selected'>1</option>";
}else{
echo"<option value='1'>1</option>";
}
if ($level == 2){
echo"<option value='2' selected='selected'>2</option>";
}else{
echo"<option value='2'>2</option>";
}
if ($level == 3){
echo"<option value='3' selected='selected'>3</option>";
}else{
echo"<option value='3'>3</option>";
}
if ($level == 4){
echo"<option value='4' selected='selected'>4</option>";
}else{
echo"<option value='4'>4</option>";
}
echo"</select>";


echo"</table>";
echo"</li>";
$i++;
}
echo"</ul>";
echo"<input type='hidden' name='level'value='level' />";
echo"<input type='submit' size='50' name='deleteuser' value='delete users' />";
echo "</form>";
echo"</div>";
}

 

So if you know how I make the $user variable the select name I would be very thankful!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.