Hi, I am stuck in a simple problem due to checkbox

The problem is that in the value attribute of checkbox I am placing a value which I want to retrieve

echo "<td><input type='checkbox' value='".$row['docid']."' name='asgn[]'>Assign</td>";

after this I am using foreach()

In the output page i get a warning saying

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\docassign.php on line 88

But as soon as I check the checkbox, the warning goes.
Earlier when I was giving Value attribute as '1', no warning was occurring

Here is the whole code

while($row=mysql_fetch_array($rundoc))
{
	echo "<td>".$row['doctor']."</td>";
	echo "<td>".$row['hospital']."</td>";
	echo "<td>".$row['expert']."</td>";
	echo "<td>".$row['phone']."</td>";
	echo "<td><input type='checkbox' value='".$row['docid']."' name='asgn[]'>Assign</td>";
	
	echo "<td><input type='submit' name='submit' value='Submit'></td>";
	echo "<tr>";
	
}


foreach($_REQUEST['asgn'] as $checkbox)
    {
   		$var = $checkbox;
	  	//echo $var;
  	}

If you just want to remove your warning then just add this

if(count($_REQUEST['asgn']))

before your foreach statement as

if(count($_REQUEST['asgn']))
foreach($_REQUEST['asgn'] as $checkbox)
{
//your code
}

But if you want to retrieve your value then do the following
Add this

echo "<form method='post' name='frm1'>";

before while() i.e. Line no1
and end it after while block as

echo '</form>';

Ok...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.