473,791 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

in_array() wierdness with arrays inside of $_POST

I am using in_array() to search for a value ("other"), in order to validate
a form.
If I pass $_POST["interests"] as the array to search PHP says that it is an
invalid datatype.
It is an array and if I copy it to another variable (i.e. $list =
$_POST["interests"];) it works fine.
The same is also true of implode().

Do you believe this is intended or is it a bug?
--
AJ Zmudosky
There are no stupid questions, but there are a LOT of inquisitive idiots.
Jul 17 '05
12 6013
AJ Z <us****@gwws.ne t> wrote in message news:<200402021 9572116807%usen et@gwwsnet>...
On 2004-02-01 22:25:57 -0800, ra************@ rediffmail.com (Rahul Anand)
said:
..
post a sample code if it still not solved.

--
Cheers,
Rahul Anand


Even with your suggestion on trim() I get the warning. Confirmed in_array()
args are in the correct order.


It works at my system [PHP 5]

[SNIP]

$_POST['key'] = array('aKey'=>' aValue','bKey'= >'bValue');

// Remove excess spaces
foreach ($_POST as $key => $val)
if(!is_array($v al))
$_POST[$key] = trim($val);

print_r($_POST) ;
exit;

[/SNIP]

Run this code to check it working. If it works, then receive the array
from a form post. I assure you that, it will execute smoothly.

You might have coded wrong, so please post the code you are trying to
execute.

--
Cheers,
Rahul Anand
Jul 17 '05 #11
On 2004-02-03 00:59:23 -0800, ra************@ rediffmail.com (Rahul Anand)
said:
...

Your code does execute without errors, and shows up.
I also ran it through in_array (searching for 'aValue') and it generated no
warnings.
However, my array also returns true for is_array(), but gives the warning.
The entire source code for the form can be seen at:
http://www.gwws.net/form.phps
If you would like it posted here I can trim it down and post it.
--
AJ Zmudosky
There are no stupid questions, but there are a LOT of inquisitive idiots.
Jul 17 '05 #12
AJ Z <us****@gwws.ne t> wrote in message news:<200402030 7093975249%usen et@gwwsnet>...
On 2004-02-03 00:59:23 -0800, ra************@ rediffmail.com (Rahul Anand)
said:
..

Your code does execute without errors, and shows up.
I also ran it through in_array (searching for 'aValue') and it generated no
warnings.
However, my array also returns true for is_array(), but gives the warning.
The entire source code for the form can be seen at:
http://www.gwws.net/form.phps
If you would like it posted here I can trim it down and post it.


I checked the code and found the reason for the error you are getting.
Here goes the explanation:

Line 10:
[SNIP]

if (is_array($_POS T["interests"])) { echo "'interests ' IS AN ARRAY<br
/>\n"; } else { echo "'interests ' IS AN ARRAY<br />\n"; }

[/SNIP]

In both case you are printing "'interests ' IS AN ARRAY".
Change the else part, and you will notice *interests* is not array in
all cases.

Reason:
PHP forms an array only when there is atleast one checkbox checked.
Because a form only sends the checked checkbox values.

Solution:
Before trying to operate on intersts array you need to test the array
with *isempty* or *isset* or *isarray*

Hope it will help.

--
Rahul Anand
Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2260
by: Bart Nessux | last post by:
How is this done in php? I've tried several variations of the following: contact_array = ($_POST, $_POST, $_POST, $_POST, $_POST); The ultimate goal is to insert the array into a table in a Mysql db.
3
10693
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if (!in_array($obj, $result)) array_push($result, $obj); } }
8
1869
by: Oeln | last post by:
If I want to check for input of an integer I've got the following (I get the form input with $input = "$_POST"): if(!ereg("^+$",$_POST)) { echo "Input is incomplete or incorrect."; } If, instead of only getting one 'input' I wanted to get n instances of input, I'd generate input fields for each of n instances I want in a for loop, then get the input with:
5
2374
by: Phil Powell | last post by:
Here is my array. Plain and simple enumerative array with values being strings. So why does this fail??? print_r(in_array('album', array_keys($boolword))); This produces FALSE or NULL. But it's right there IN the array!! What
6
2275
by: Fnark! | last post by:
I am creating a shopping cart using PHP Version 4.1.2. I am creating and registering a cart object in a session. The cart object contains an array of arrays called $order whose elements are a collection of $orderline associative arrays which, in turn, hold the global POST values key 'order_code' and value 'qty' as passed in from another page. My problem is (shown by using print_r to print out the contents of the arrays) each time I...
8
1616
by: mantrid | last post by:
Hello Im having problems working out why the following code does not work. I dont think its the sql as the error occurs on the first update which ever one is put there ($q1 or $q2). Ive swapped then around to test this. Help greatly appreciated The error is Unknown column 'A' in 'field list' but there is no field 'A'. im thinking that the 'A' may be first letter of the word Array, as if it is using this as a variable, but i dont know...
0
1089
by: rich | last post by:
I have 2 arrays. I am trying to use in_array with and it doesn't seem to be working. I have done a print_r of each one for my test data. Array $primsecA is below: Array ( =Array ( =1 =Primary ) => Array ( =2 =Secondary ) =Array ( =3 =Skin Protectors ) ) Array $specprimA is below.
3
1889
by: Sonnich | last post by:
The following code is an exact copy of my current code. The idea is to check 2 parts (of string arrays), and add those only once to a common array. I check for existance of an array in a string, as the string contain more data that just .... well, the part from the options array is there, then it is added to the folders array. The problem is the line: if(!in_array($folders, $options1)) which works in the first case, but not...
0
1103
by: Jim Carlock | last post by:
$aThePosts = array_change_key_case($_POST, CASE_LOWER); define("CONTACT_IS_LOCAL", 0); define("CONTACT_IS_REMOTE", 1); /* $aWho contains an array of arrays (contact details) * array( * array(0, CONTACT_IS_LOCAL, "My Local Contact", * "123 Any Street", "Suite 123", * "Phoenix", STATE_ARIZONA, "01234-5678",
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.