Checking if multidimensional array is empty?


Posted on 16th Feb 2014 07:03 pm by admin

I have a for with multiple test input fields. Specifically the user submits multiple names and ages. The form is submitted using the POST method. Here is a code snippet:

Code:
<form action = {$_SERVER['PHP_SELF']} method = 'post' >

for($i=1; $i<=10; $i++){

<input type = 'text' name = 'name[]' size ='25' maxlength = '50' />
<input type = 'text' name = 'age[]' size ='25' maxlength = '50' />

}

<input type="submit" />

</form>

I want to check if the user clicks submits without entering values in the text fields.

I have tried this:

Code: if(empty($_POST['name']) && empty($_POST['age'])){

echo "All the entries were blank, please enter name(s) and age(s) on the left and click submit. Thank you.";

}

However, this doesn't parse as "true" when I click submit with the fields empty.

Is it not possible to use "empty()" with arrays and/or multidimensional arrays?

No comments posted yet

Your Answer:

Login to answer
55 Like 28 Dislike
Previous forums Next forums
Other forums

Not adding to db
Hi, I can't figure out why it won't add the record to the database. It's just a simple form to get

firefox wouldnt stream mp3 files completely from my php page
hi everyone,
I have a php file trying to read and stream mp3 files. It works fine in IE but my pr

How do I use a global footer..?
If my index.php has a bole bunch of if functions and exit's in them

Using system() and bringing back the results
I am aware that you can use system() within PHP to execute system commands, but I was wondering if t

utf8_general_ci error ??
I have all kinds of data to be inserted in database table

//I am getting this error

Yo

Lack of simpleXML Documentation
What is up with this.

Look at: http://www.php.net/manual/en/function.simplexml-load-file.php<

All possible combinations of Strings from table in PL/SQL
Hi,

I am trying to figure out how to build a list of all possible string combinations fro

Revoking alter any table from a schema
Hi All,

i am working in Oracle 10g.
my requirement is to revoke all kind of DDL oper

WS-Security PL/SQL Forms
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - P

php global variable
how can we create global variable so we can use its value in any form.. Please give example to

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash