473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

"Array to String Conversion" error when constructing a multi-dimensional array

Hi,

I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

Thanks
Neil.

Jan 17 '07 #1
26 6238
drako wrote:
Hi,

I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

Thanks
Neil.
Hi Neil,

Your code looks perfectly OK to me.
Are you 100% sure this is where the error is thrown?
Did you try:
<pre>
<?php print_r($_POST); ?>
</pre>

Does it produce all used postvars you expect?

Regards,
Erwin Moller
Jan 17 '07 #2
Erwin,

I have tried <?php print_r($_POST); ?>, and it outputs all the POST
vars that were submitted. So now problem here.

And the error is thrown at the line that begins
"$_SESSION["increment"][$x] ........"

I have tried this code on two different systems (5.1.6 on OSX, and
5.2.0 on NetBSD), and the same error keeps occuring.

Very puzzling.

Neil.
Erwin Moller wrote:
drako wrote:
Hi,

I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

Thanks
Neil.

Hi Neil,

Your code looks perfectly OK to me.
Are you 100% sure this is where the error is thrown?
Did you try:
<pre>
<?php print_r($_POST); ?>
</pre>

Does it produce all used postvars you expect?

Regards,
Erwin Moller
Jan 17 '07 #3
drako wrote:
Hi,

I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
Try doing <?php print_r($_SESSION["increment"]); ?here ... (*)
$x = 0 // Counter - This will be
incremented
(*) do you have any code in here?
What does <?php print_r($increment); ?tell you?

(*) ... and an other <?php print_r($_SESSION["increment"]); ?here.
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
Jan 17 '07 #4
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" =>
$_POST["increment_comm_date1"],
"increment_comm_date2" =>
$_POST["increment_comm_date2"],
"increment_comm_date3" =>
$_POST["increment_comm_date3"]);

echo '3: ';print_r($_SESSION["increment"]);exit;

<------->
The output is:

1: 1
2:
3: 1A
I'm still no wiser as to what is going on here....

Rgds
Neil.
Heiko Richler wrote:
drako wrote:
Hi,

I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();

Try doing <?php print_r($_SESSION["increment"]); ?here ... (*)
$x = 0 // Counter - This will be
incremented

(*) do you have any code in here?
What does <?php print_r($increment); ?tell you?

(*) ... and an other <?php print_r($_SESSION["increment"]); ?here.
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);

Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
Jan 17 '07 #5
"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';
I don't understand what this $increment variable has to do with anything.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Jan 18 '07 #6


Quote:
I don't understand what this $increment variable has to do with anything.
It doesn't actually relate to anything; but I suspect it was suggested
just to see if anything was output - and nothing was output.

I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.

I now suspect this is session-related in someway. As the code looks OK,
the problem arises from elsewhere....

Kimmo Laine wrote:
"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';

I don't understand what this $increment variable has to do with anything.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Jan 18 '07 #7
Rik
drako wrote:
Don't fix bottom-posting, fix topposting.....
Kimmo Laine wrote:
>"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.googleg roups.com...
>>OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';

I don't understand what this $increment variable has to do with
anything.

It doesn't actually relate to anything; but I suspect it was
suggested just to see if anything was output - and nothing was output.

I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.

I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....
Nope.
Keep in mind, that on strings, the [] will get or set the character of the
string at that particular location. My suspicion is that you don't give us
the real code (for where would the incrementation take place?), and you
turn the array into the string ( or number) '1' somewhere. (This often
happens when you use the return of a function (true) that works be a
reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a string by
accident. On the second loop, if $x = 1, that's the second position in the
string (which was not previously set). You try to set a character to an
array, so the array is converted to a string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1. Hence
resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual overriding
on $_SESSION["increment"] takes place.
--
Rik Wasmus
Jan 18 '07 #8
Rik wrote:
drako wrote:
Don't fix bottom-posting, fix topposting.....
>Kimmo Laine wrote:
>>"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.google groups.com...
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';

I don't understand what this $increment variable has to do with
anything.

It doesn't actually relate to anything; but I suspect it was
suggested just to see if anything was output - and nothing was output.

I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.

I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....

Nope.
Keep in mind, that on strings, the [] will get or set the character of the
string at that particular location. My suspicion is that you don't give us
the real code (for where would the incrementation take place?), and you
turn the array into the string ( or number) '1' somewhere. (This often
happens when you use the return of a function (true) that works be a
reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a string by
accident. On the second loop, if $x = 1, that's the second position in
the string (which was not previously set). You try to set a character to
an array, so the array is converted to a string ('Array'), then it takes
the
first character ('A') from that string, and put it at position 1. Hence
resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual
overriding on $_SESSION["increment"] takes place.
Damn Rik, sometimes you are scaringly smart.
That sounds like a very probable scenario you described and deducted from
the sparse information given.
Respect!

Erwin Moller
Jan 18 '07 #9
drako wrote:
I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?
There doesn't seem to be anything wrong with the code you posted (except
for a missing semicolon after $x = 0), so I suspect the problem lies
somewhere in your other code.

Because of this missing semicolon, I suspect you have chopped out a
section of code between '$x=0' and '$_SESSION["increment"][$x]=array(...)'.
That is almost certainly where your problem lies. In particular, I think
you may have assigned some non-integer value to $x at some point.

Do 'print_r($x);' just before the error happens and see what you see.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 18 '07 #10
You are correct in assuming that I chopped out a line when I posted
this...

The missing line between '$x=0' and
'$_SESSION["increment"][$x]=array(...)'.

is

if(isset($_SESSION["increments"])) {$x =
count($_SESSION["increments"]);}

The purpose is to count the number of entries in the array - if count
returns '5', then the last value of $x would have been 4, so we can
assign '5' as the next value in the array.

Could this be the offending line...

Toby Inkster wrote:
drako wrote:
I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

There doesn't seem to be anything wrong with the code you posted (except
for a missing semicolon after $x = 0), so I suspect the problem lies
somewhere in your other code.

Because of this missing semicolon, I suspect you have chopped out a
section of code between '$x=0' and '$_SESSION["increment"][$x]=array(...)'.
That is almost certainly where your problem lies. In particular, I think
you may have assigned some non-integer value to $x at some point.

Do 'print_r($x);' just before the error happens and see what you see.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Jan 18 '07 #11

Sorry, the extra line of code above should have read:

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}

I just noticed the typo, in case anyone has been sharp enough to spot
it...
drako wrote:
You are correct in assuming that I chopped out a line when I posted
this...

The missing line between '$x=0' and
'$_SESSION["increment"][$x]=array(...)'.

is

if(isset($_SESSION["increments"])) {$x =
count($_SESSION["increments"]);}

The purpose is to count the number of entries in the array - if count
returns '5', then the last value of $x would have been 4, so we can
assign '5' as the next value in the array.

Could this be the offending line...

Toby Inkster wrote:
drako wrote:
I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.
>
Any suggestions or hints ?
There doesn't seem to be anything wrong with the code you posted (except
for a missing semicolon after $x = 0), so I suspect the problem lies
somewhere in your other code.

Because of this missing semicolon, I suspect you have chopped out a
section of code between '$x=0' and '$_SESSION["increment"][$x]=array(...)'.
That is almost certainly where your problem lies. In particular, I think
you may have assigned some non-integer value to $x at some point.

Do 'print_r($x);' just before the error happens and see what you see.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Jan 18 '07 #12
drako wrote:
Sorry, the extra line of code above should have read:

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
Do you know you do not need $x?

See "Creating/modifying with square-bracket syntax" at
http://www.php.net/manual/en/language.types.array.php

Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
Jan 18 '07 #13
Rik
drako wrote:
drako wrote:
>You are correct in assuming that I chopped out a line when I posted
this...

The missing line between '$x=0' and
'$_SESSION["increment"][$x]=array(...)'.

is

if(isset($_SESSION["increments"])) {$x =
count($_SESSION["increments"]);}

The purpose is to count the number of entries in the array - if count
returns '5', then the last value of $x would have been 4, so we can
assign '5' as the next value in the array.

Could this be the offending line...
Sorry, the extra line of code above should have read:

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}

I just noticed the typo, in case anyone has been sharp enough to spot
it...
But that's not it afaik. See the comment about just using empty [], this
will just add an array-value to the end.

However, there's something else going on in the adding. Posting the total
code that works on $_SESSION["increment"] woudl speed up the process :-).

You probably have a $_SESSION["increment"] = something(); somehere, where
the function just returns true instead of a processed array, casting it to
the '1' string.
--
Rik Wasmus
Jan 18 '07 #14
Rik
Erwin Moller wrote:
Rik wrote:
>>I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....

Nope.
Keep in mind, that on strings, the [] will get or set the character
of the string at that particular location. My suspicion is that you
don't give us the real code (for where would the incrementation take
place?), and you turn the array into the string ( or number) '1'
somewhere. (This often happens when you use the return of a function
(true) that works be a reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a
string by accident. On the second loop, if $x = 1, that's the
second position in the string (which was not previously set). You
try to set a character to an array, so the array is converted to a
string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1.
Hence resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual
overriding on $_SESSION["increment"] takes place.

Damn Rik, sometimes you are scaringly smart.
Well, that remains to be seen, but thank you, would be nice if I would get
paid that way though :-)
That sounds like a very probable scenario you described and deducted
from the sparse information given.
It helps that I cannot get the difference of array_walk() and array_map in
my head, so I'm used to seeing some '1''s or 'A's..

Now let's get the OP to post the code he uses in it's entirety to claim my
fame :-)
--
Rik Wasmus
Jan 18 '07 #15
OK,

Here is the code in its entireity:

[It is wrapped around an IF statement to process upon a certain
condition].

if($_POST['increment'] == 1) {

$x = 0;

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}
Rik wrote:
Erwin Moller wrote:
Rik wrote:
>I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....

Nope.
Keep in mind, that on strings, the [] will get or set the character
of the string at that particular location. My suspicion is that you
don't give us the real code (for where would the incrementation take
place?), and you turn the array into the string ( or number) '1'
somewhere. (This often happens when you use the return of a function
(true) that works be a reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a
string by accident. On the second loop, if $x = 1, that's the
second position in the string (which was not previously set). You
try to set a character to an array, so the array is converted to a
string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1.
Hence resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual
overriding on $_SESSION["increment"] takes place.
Damn Rik, sometimes you are scaringly smart.

Well, that remains to be seen, but thank you, would be nice if I would get
paid that way though :-)
That sounds like a very probable scenario you described and deducted
from the sparse information given.

It helps that I cannot get the difference of array_walk() and array_map in
my head, so I'm used to seeing some '1''s or 'A's..

Now let's get the OP to post the code he uses in it's entirety to claim my
fame :-)
--
Rik Wasmus
Jan 18 '07 #16
Rik
drako wrote:
OK,

Here is the code in its entireity:

[It is wrapped around an IF statement to process upon a certain
condition].

if($_POST['increment'] == 1) {

$x = 0;

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}
Is your $_SESSION['increment'] accessed/altered anywhere else in the
script? Check for it.
Also, add this before "if($_POST['increment'] == 1)":

if(isset($_SESSION['increment'])) var_dump($_SESSION['incremenet']);

Most likely, you overwrite the $_SESSION['increment'] somewhere else in
your code, so it get's cast to a string. Check your code for every
'$_SESSION['increment']= ', and carefully consider the return of the
function after it...
--
Rik Wasmus
Jan 19 '07 #17
On Jan 19, 5:15 am, "Rik" <luiheidsgoe...@hotmail.comwrote:
drako wrote:
OK,
Here is the code in its entireity:
[It is wrapped around an IF statement to process upon a certain
condition].
if($_POST['increment'] == 1) {
$x = 0;
if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}Is your $_SESSION['increment'] accessed/altered anywhere else in the
script? Check for it.
Also, add this before "if($_POST['increment'] == 1)":

if(isset($_SESSION['increment'])) var_dump($_SESSION['incremenet']);

Most likely, you overwrite the $_SESSION['increment'] somewhere else in
your code, so it get's cast to a string. Check your code for every
'$_SESSION['increment']= ', and carefully consider the return of the
function after it...
--
Rik Wasmus
Concerning your earlier post, great deductive reasoning, Rik. *bows*

Just to reiterate to the OP, you need to check if you're assigning
$_SESSION['increment'] a function's return value, or possibly even
directly a string, at some other point (potentially in a different
file, since it is a session variable).

Also, you could a foreach loop, so as not to manually maintain the
array's index.
---
Curtis

Jan 20 '07 #18

I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort' in
order to process the array data.

Thanks for all your help and suggestions on this one.

Rgds
Neil.
Curtis wrote:
On Jan 19, 5:15 am, "Rik" <luiheidsgoe...@hotmail.comwrote:
drako wrote:
OK,
Here is the code in its entireity:
[It is wrapped around an IF statement to process upon a certain
condition].
if($_POST['increment'] == 1) {
$x = 0;
if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}Is your $_SESSION['increment'] accessed/altered anywhere else in the
script? Check for it.
Also, add this before "if($_POST['increment'] == 1)":

if(isset($_SESSION['increment'])) var_dump($_SESSION['incremenet']);

Most likely, you overwrite the $_SESSION['increment'] somewhere else in
your code, so it get's cast to a string. Check your code for every
'$_SESSION['increment']= ', and carefully consider the return of the
function after it...
--
Rik Wasmus

Concerning your earlier post, great deductive reasoning, Rik. *bows*

Just to reiterate to the OP, you need to check if you're assigning
$_SESSION['increment'] a function's return value, or possibly even
directly a string, at some other point (potentially in a different
file, since it is a session variable).

Also, you could a foreach loop, so as not to manually maintain the
array's index.
---
Curtis
Jan 22 '07 #19
Rik
drako wrote:
I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort' in
order to process the array data.
[despirately trying to claim the fame]

Well, you're copying the POST to the SESSION somewhere in your code in that
case, as it is not a PHP feature. This works fine:
<?php
session_start();
if(!isset($_POST['submit'])){
$_SESSION['increment'] = 'This is the session value';
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="increment">
<input type="submit" name="submit">
</form>
<pre>
<?php
echo "The SESSION is {$_SESSION['increment']}\n";
echo "The POST is {$_POST['increment']}\n";
?>
</pre>

And upon posting "This is the post value" in correctly displays:
The SESSION is This is the session value
The POST is This is the post value

I'd say my claim you've turned it into a string stands :-)

[/end of sad little claim here]
--
Rik Wasmus
Jan 22 '07 #20
Rik wrote:
drako wrote:
>I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort' in
order to process the array data.

[despirately trying to claim the fame]

Well, you're copying the POST to the SESSION somewhere in your code in that
case, as it is not a PHP feature. This works fine:
<?php
session_start();
if(!isset($_POST['submit'])){
$_SESSION['increment'] = 'This is the session value';
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="increment">
<input type="submit" name="submit">
</form>
<pre>
<?php
echo "The SESSION is {$_SESSION['increment']}\n";
echo "The POST is {$_POST['increment']}\n";
?>
</pre>

And upon posting "This is the post value" in correctly displays:
The SESSION is This is the session value
The POST is This is the post value

I'd say my claim you've turned it into a string stands :-)

[/end of sad little claim here]
Or, maybe register_globals is enabled?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '07 #21
Rik
Jerry Stuckle wrote:
Rik wrote:
>drako wrote:
>>I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort'
in order to process the array data.

Well, you're copying the POST to the SESSION somewhere in your code
in that case, as it is not a PHP feature. This works fine:

Or, maybe register_globals is enabled?
That would not overwrite the $_POST & $_SESSION arrays, and even then, the
$_SESSION would win the $increment, and the $_POST value would be
discarded.
--
Rik Wasmus
Jan 23 '07 #22
Rik wrote:
Jerry Stuckle wrote:
>Rik wrote:
>>drako wrote:
I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort'
in order to process the array data.
Well, you're copying the POST to the SESSION somewhere in your code
in that case, as it is not a PHP feature. This works fine:
Or, maybe register_globals is enabled?

That would not overwrite the $_POST & $_SESSION arrays, and even then, the
$_SESSION would win the $increment, and the $_POST value would be
discarded.
As posted, that is true. But we don't know what other code he has
which isn't posted. Perhaps he has something like $increment=4; in
another place in his program.

Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '07 #23
On Jan 23, 4:20 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.
Indeed, but it seems quite rare that change would be made to the
default order. Also, the OP stated above, he has register_globals off.

--
Curtis

Jan 24 '07 #24
Rik
Jerry Stuckle wrote:
Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.
Ah, this is a setting? I memorized GPCS, it never occured to me this was
configurable. Learn something new every day :-)

--
Rik Wasmus
Jan 24 '07 #25
Curtis wrote:
On Jan 23, 4:20 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.

Indeed, but it seems quite rare that change would be made to the
default order. Also, the OP stated above, he has register_globals off.

--
Curtis
Curtis,

Yes, it's unusual, but not unheard of.

As for register_globals being off. I've had people claim that is the
case - but then later found out it wasn't. They were looking at the
wrong php.ini file and/or had it overridden. I never trust any settings
without seeing what phpinfo() has to say.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 24 '07 #26
On Jan 24, 9:06 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Curtis wrote:
On Jan 23, 4:20 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.
Indeed, but it seems quite rare that change would be made to the
default order. Also, the OP stated above, he has register_globals off.
--
CurtisCurtis,

Yes, it's unusual, but not unheard of.

As for register_globals being off. I've had people claim that is the
case - but then later found out it wasn't. They were looking at the
wrong php.ini file and/or had it overridden. I never trust any settings
without seeing what phpinfo() has to say.
That's a good point, Jerry. Ruling things out too early can impede
problem-solving. When I was developing one project, I didn't realize my
host had register_globals on, ugh, quite a pain, if only I had been
wise enough to check phpinfo() before hand. Now I know better, at
least.

--
Curtis

Jan 25 '07 #27

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

Similar topics

2
by: Miki Tebeka | last post by:
Hello All, I'm shipping an application using py2exe. With Python2.3 it worked fine but when switching to Python2.4 I started getting "warning: string/unicode conversion" all over the place. ...
7
by: ma740988 | last post by:
The string object value_f doesn't produce the right output. At issue, - I suspect - is the conversion from string to int with istringstream. An alternate approach? Thanks in advance #include...
0
by: MLH | last post by:
Is an apostrophe a character of special significance to MySQL in a way that would cause "Bob's dog" to become translated into a 12-character string when typed into a MySQL memo field? If I type...
10
by: =?Utf-8?B?RWxlbmE=?= | last post by:
I am surprised to discover that c# automatically converts an integer to a string when concatenating with the "+" operator. I thought c# was supposed to be very strict about types. Doesn't it seem...
3
by: Ady1 | last post by:
Hi, I'm getting this error intermitantly in a custom configuration section in my ASP.NET website. From what I can see 0.175 is a valid string to be converted to a decimal! And most of the time...
6
by: Don Lancaster | last post by:
I need to progrmatically do this inside a loop this.fh03.value = fixFloat (Harms, numPoints) ; with the numbers changing per an index. If I try curHvals = "03" ; // (derived from...
6
by: =?Utf-8?B?SmVmZg==?= | last post by:
I thought this would already be covered here, but my search turned up nothing. In VS2005, if I use "String" to define a new variable/class, it colors it in the Aqua color as it does other...
10
by: Dave griffiths | last post by:
Hi all Using VB2005 on Vista with a Norwegian locale setup. The test program has 3 textboxes the sum held in txt3. Using the code below, txt2 conversion causes an error when it is left empty....
1
by: dhtmlkitchen | last post by:
Why does "foo" instanceof String return false? It just seems counterintuitive to me. I mean, sure, I can always check the constructor: var fooVar = "foo"; var isString =...
5
by: mvmashraf | last post by:
Hi to all.... I have spent some time browsing for a solution to the following error but have unfortunatly not found any solution yet ,Please any help would be much appreciated.......
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
tracyyun
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...
0
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...

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.