Hi All!
I wonder if there is anyone who have some ideas of how to compress this code to a minimum. If you have a lot of form fields in a form it would take some time to write this code for each field.
// check if empty // if (empty($Fname)) { $error['emptyFname'] = 'Empty Fname.'; } else if (empty($Lname)){ $error['emptyLname'] = 'Empty Lname.'; } else if (empty($IDcode)){ $error['emptyIDcode'] = 'Empty IDcode.'; } else if (empty($Region)){ $error['emptyRegion'] = 'Empty Region.'; } else if (empty($Depart)){ $error['emptyDepart'] = 'Empty Depart.'; } else if (empty($Email)){ $error['emptyEmail'] = 'Empty Email.'; } else {
Thanks!
Well, if that's what you really want:
$array = array('Fname', 'Lname', 'IDcode', 'Region', 'Depart', 'Email'); foreach ($array as $value) { if (empty($$value)) { $error['empty' . $value] = 'Empty ' . $value . '.'; } }
It's prefect!
This will check for empty fields but it still submit the empty field to the database. how do I prevent it from being submitted+
thanks!
how do I prevent it from being submitted+
Just check for errors.
im not really with you... =)
can u explain little more?
I think you'd have to explain a little more. This is the first time you've mentioned a database, and is in fact the first time you mentioned even having a problem.