Jump to content

Using foreach to echo error. But error is given when not set...


cs.punk

Recommended Posts

Uhm Im kinda stuck...

 

 

 

<?php
if (isset($error))
 {echo "<p class='error'>The following errors were found:</p>
 			";
	print_r ($error);

  // missing fields	  
  $error['empty'] = array();
  foreach ($error['empty'] as $v)
  	{echo "<p class='error'>$v</p>";
	}

  // invalid size
  foreach ($error['size'] as $v)
  	{echo "<p class='error'>$v</p>";
	}

  // invalid format
  foreach ($error['format'] as $v)
  	{echo "<p class='error'>$v</p>";
	}
 }


// Coming from the xhtml form
   if (!empty($_POST['title']))
   	{$rdata['title'] = mysqli_real_escape_string($con, $_POST['title']);
}
   else
    {$error['empty'][] = "You have not entered a title."; 
}

   if (!empty($_POST['desc']))
   	{$rdata[''] = mysqli_real_escape_string($con, $_POST['desc']);
}
   else
    {$error['empty'][] = "You have not entered a descreption."; 
}
?>

 

But every time no error from one array is found but an error is found form another is still uses foreach on it.. and since its not set as an array it gives an error. I cant use

$error['empty'] = array();

because it would blank it when there is an error...

Warning: Invalid argument supplied for foreach() in D:\Chris\reco\xampplite\htdocs\admin\admin.php on line 164

 

A isset for each array? Is there an easier way?

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.