Jump to content

[SOLVED] php chechkbox, Warning: Invalid argument supplied for foreach() why ?


plodos

Recommended Posts

if(isset($_FILES['paper'])){

$file_name = $_FILES['paper']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));

$q		= "insert into paper set title='{$_REQUEST['title']}', abstract='{$_REQUEST['abstract']}', 
keywords='{$_REQUEST['keywords']}',  authors='{$_REQUEST['authors']}', ext='$file_ext', user='{$_SESSION['id']}',
status='new', datum='date()' ";
$result	= mysql_query($q);
$fid		= mysql_insert_id();
move_uploaded_file($_FILES['paper']['tmp_name'], 'sweet_papers/'.$fid.$file_ext);
//problem part
$state=$_POST['state'];
foreach ($state as $statename)
{
$qu = "insert into paper_research_field set paper='{$fid}', d='{$statename}'";
	$err = mysql_query($qu);
	if(!$err)
	{
                 header("Location:".$_SERVER['HTTP_REFERER']."?wrong_code21=true");
        }
}
//problem part end
header('Location: http://'.$_SERVER['SERVER_NAME'].'/my_papers.php');

}

 

i want to add these checkbox values with foreach

but it gives this Warning: Invalid argument supplied for foreach() WHY ??

<tr>
<td><input type='checkbox' name='state[]' value='1'>Acoustics</td>
<td><input type='checkbox' name='state[]' value='2'>Antennas/RF Front Ends </td>
</tr>

i changed it

//$state=$_POST['state'];
foreach($_POST['state'] as $statename)
{
	$qu = "insert into paper_research_field set paper='{$fid}', id='{$statename}'";
	echo $q;
	$err = mysql_query($qu);
	if(!$err)
	{
		header("Location:".$_SERVER['HTTP_REFERER']."?wrong_code21=true");
    }
}

but still same problem Warning: Invalid argument supplied for foreach()

Archived

This topic is now archived and is closed to further replies.

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