Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP foreach loop problem.

Posted on 2009-04-15
3
Medium Priority
?
218 Views
Last Modified: 2012-05-06
Can you help me sort out this function... $field is an array of field names that need to be checked.
For example:
$field = ['cus_id', 'cus_fname', 'cus_sname']

function isEmpty($field, $msg = NULL)
      {            
            if ($msg == NULL) {$msg = 'Field Empty';}
            foreach($field as $key => $value) {
                  if(!isset($_POST[$value]) || (empty(trim($_POST[$value]))))
                  {
                        $this->_errorList[] = array("field" => $value, "msg" => $msg);
                        return false;
                  }
                  else
                  {
                        return true;
                  }
            }
      }

I am getting this error:
Fatal error: Can't use function return value in write context

Thanks
Nick
0
Comment
Question by:Chimeraza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 1000 total points
ID: 24148616
you can't combine empty with a function call. See http://www.php.net/empty Use as condition:
trim($_POST[$value]) == ''
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24148723
empty() only works on variables. trim() returns a string. I think that is your problem. Try it with strlen instead of empty. If I am write that will cure your problem.
0
 
LVL 3

Author Closing Comment

by:Chimeraza
ID: 31570465
First come first serve! Thanks
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question