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. 12 6012
AJ Z wrote: 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.
$_POST['whatever'] isn't an array $_POST is an array, but yes you will
have to make it into an array first using something like
$data = explode(",", $_POST['interests']);
then it's an array.
~Cameron
On Sun, 01 Feb 2004 17:50:37 +0000, Cameron <fo*@bar.invali d> wrote: AJ Z wrote: 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?
$_POST['whatever'] isn't an array $_POST is an array, but yes you will have to make it into an array first using something like
$data = explode(",", $_POST['interests']);
then it's an array.
$_POST['whatever'] _can_ be an array. The OP said it was.
Consider:
<input type="checkbox" name="whatever[]" value="one">
<input type="checkbox" name="whatever[]" value="two">
<input type="checkbox" name="whatever[]" value="three">
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
On Sun, 1 Feb 2004 09:19:32 -0800, AJ Z <us****@gwws.ne t> wrote: 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?
Are you sure it's an array? Use var_dump, or is_array to check.
Is it produced by a series of input elements named "whatever[]" (note the use
of [] - required for PHP to produce an array)?
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
On 2004-02-01 10:18:17 -0800, Andy Hassall <an**@andyh.co. uk> said: On Sun, 1 Feb 2004 09:19:32 -0800, AJ Z <us****@gwws.ne t> wrote:
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?
Are you sure it's an array? Use var_dump, or is_array to check.
Is it produced by a series of input elements named "whatever[]" (note
the use of [] - required for PHP to produce an array)?
-- Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
Yes, it is an array, I used is_array and var_dump at the suggestion of
others, but I am wondering why it doesn't work as $_POST["interests"], but
it does as $list (if $list = $_POST["interests"] -- it should be exactly
the same). It is an array due to what you suggested to Cameron (checkboxes
with a name of "something[]")
--
AJ Zmudosky
There are no stupid questions, but there are a LOT of inquisitive idiots.
On Sun, 1 Feb 2004 13:39:48 -0800, AJ Z <us****@gwws.ne t> wrote: On 2004-02-01 10:18:17 -0800, Andy Hassall <an**@andyh.co. uk> said:
On Sun, 1 Feb 2004 09:19:32 -0800, AJ Z <us****@gwws.ne t> wrote:
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?
Are you sure it's an array? Use var_dump, or is_array to check.
Is it produced by a series of input elements named "whatever[]" (note the use of [] - required for PHP to produce an array)?
Yes, it is an array, I used is_array and var_dump at the suggestion of others, but I am wondering why it doesn't work as $_POST["interests"], but it does as $list (if $list = $_POST["interests"] -- it should be exactly the same). It is an array due to what you suggested to Cameron (checkboxes with a name of "something[]")
Please post a small runnable example that demonstrates your problem.
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
Andy Hassall <an**@andyh.co. uk> wrote in message news:<67******* *************** **********@4ax. com>... On Sun, 1 Feb 2004 13:39:48 -0800, AJ Z <us****@gwws.ne t> wrote:
On 2004-02-01 10:18:17 -0800, Andy Hassall <an**@andyh.co. uk> said:
On Sun, 1 Feb 2004 09:19:32 -0800, AJ Z <us****@gwws.ne t> wrote:
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?
Are you sure it's an array? Use var_dump, or is_array to check.
Is it produced by a series of input elements named "whatever[]" (note the use of [] - required for PHP to produce an array)?
Yes, it is an array, I used is_array and var_dump at the suggestion of others, but I am wondering why it doesn't work as $_POST["interests"], but it does as $list (if $list = $_POST["interests"] -- it should be exactly the same). It is an array due to what you suggested to Cameron (checkboxes with a name of "something[]")
Please post a small runnable example that demonstrates your problem.
If it is verified by *is_array* that $_POST["interests"] is an array,
then i guess you must be sending arguments in wrong order.
Please verify the syntax of *in_array*:
bool in_array ( mixed needle, array haystack [, bool strict] )
post a sample code if it still not solved.
--
Cheers,
Rahul Anand
On 2004-02-01 13:52:47 -0800, Andy Hassall <an**@andyh.co. uk> said:
... Please post a small runnable example that demonstrates your problem. -- Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
<?php
if ($_POST["action"] == "doprocform ") {
// Remove excess spaces
foreach ($_POST as $key => $val) { $_POST[$key] = trim($val); }
// Validate form
// Do other checks here
if (in_array("othe r", $_POST["interests"]) && $_POST["other_explanat ion"]
== "") { $err = true; }
// Compress listing arrays
$interests_list = implode(", ", $_POST["interests"]);
if ($err) {
// Display error message(s)
} else {
// Transmit form (via e-mail or to DB, etc.)
}
} else {
// Display form (STND. HTML)
}
?>
The above use of in_array() and implode() generates warnings, under both
PHP 4.3.3 and PHP 5.0.0b3.
--
AJ Zmudosky
There are no stupid questions, but there are a LOT of inquisitive idiots.
AJ Z <us****@gwws.ne t> wrote in message news:<200402012 2060316807%usen et@gwwsnet>... On 2004-02-01 13:52:47 -0800, Andy Hassall <an**@andyh.co. uk> said: .. Please post a small runnable example that demonstrates your problem. -- Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space> <?php if ($_POST["action"] == "doprocform ") { // Remove excess spaces foreach ($_POST as $key => $val) { $_POST[$key] = trim($val); }
The problem is here
*************** **************
$_POST[$key] = trim($val);
*************** **************
You can not trim an array. If you enable the notice errors, (a good
practice to catch errors during development) you will get an error
from PHP Parser.
In your case the $val will be converted to string and trim function
will return a string value "Array".
Modify the lines with:
foreach ($_POST as $key => $val)
{
if(!is_array($v al))
$_POST[$key] = trim($val);
}
// Validate form // Do other checks here if (in_array("othe r", $_POST["interests"]) && $_POST["other_explanat ion"] == "") { $err = true; } // Compress listing arrays $interests_list = implode(", ", $_POST["interests"]); if ($err) { // Display error message(s) } else { // Transmit form (via e-mail or to DB, etc.) } } else { // Display form (STND. HTML) } ?> The above use of in_array() and implode() generates warnings, under both PHP 4.3.3 and PHP 5.0.0b3.
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.
--
AJ Zmudosky
There are no stupid questions, but there are a LOT of inquisitive idiots. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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);
}
}
|
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:
|
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
|
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...
| |
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...
|
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.
|
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...
|
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",
|
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...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |