0

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;
  	}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mahavir123
0

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...

Edited by mahavir123: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.