PHP Combox box problem. Help Please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jimgym1989
Forum Newbie
Posts: 10
Joined: Thu May 14, 2009 8:31 am

PHP Combox box problem. Help Please!

Post by jimgym1989 »

Hi everyone,
I'm having a problem on passing values from my combo box. Let me show you first my code. I have 2 files test.php and view.php.
This is what's inside the test.php

Code: Select all

while($row = mysql_fetch_array($strSQL)){
		$data .= "<tr>";
		$data .= "<td>";
    $data .= "<input type='checkbox' class='memberchk' name='membersID[]' value='".$row['member_id']."' />";
    $data .= "</td>";
	$data .="<td>";
	$data .= "".$row['name'];
	$data .="</td>";
	
	$data .="<td>";
	$data .= "<select name='access[]'>";
		
		if($row['access'] == 'member'){
			$data .="<option selected value='member'>Member</option>";
		}
		else{
			$data .="<option value='member'>Member</option>";
		}
		
		if($row['access'] == 'admin'){
			$data .="<option selected value='admin'>Admin</option>";
		}
		else{
			$data .="<option value='admin'>Admin</option>";
		}
	$data .="</select>";
	
	$data .="</td>";
	
	$data .= "</tr>";
} 
This is my view.php

Code: Select all

$member_id = $_POST['membersID'];
$access = $_POST['access'];
$size = sizeof($member_id);

for($i=0;$i<$size;$i++){
echo "Member id: ".$member_id[$i]."</br>";
echo "Access: ".$access[$i];
echo "</br>";
}
In this code is just a display on every values of my $access and $member_id array variables
These are the values in my database
member_id | names |access|
---------------------------------------------------
1 |Jim | member |
2 |Elson | admin |
3 |Jezel | member |
4 |Rose | admin |
----------------------------------------------
As you can see on the codes above, it has a checkbox and a combo box, and everytime I click on the button update, it will display values on what's inside the $access and $member_id array variables.
My problem here is that every time I change Jezel as an admin, the $access = $_POST['access'] will still display member,
But if I try to change Jim as an admin, $access = $_POST['access'] will display admin, there will be no problem..
There's also another problem, I need to checked all the checkboxes on the list, so that Jezel's access will changed.
What's the problem with this?
By the way, $access and $member_id is an array.

I was really having a hard time explaining this problem. Just ask me if there's something unclear to you regarding on my explanation. Thanks! :D
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: PHP Combox box problem. Help Please!

Post by Jade »

Try doing a print_r() of your $_POST variables so you can see what data is going into each array. The only thing I can think of off the top of my head is that your array index is getting offset somehow.

Code: Select all

print_r($_POST['membersID']);
print_r($_POST['access']);
$size = count($_POST['membersID']);

for($i=0;$i<$size;$i++){
echo "Member id: ".$_POST['membersID'][$i]."</br>";
echo "Access: ".$_POST['access'][$i];
echo "</br>";
}
Post Reply