[PHP] [SOLVED] Re: [PHP] disappearing array?

2007-09-21 Thread Jas
Found the problem. I had a typo on my conditional statement.

if( $fix-ValArray( $_POST['add_order_items'] === -1 ) ) {
 $errors['add_order_array'] = $erlink;
}

Should have been:
if( $fix-ValArray( $_POST['add_order_items'] ) === -1 ) {
 $errors['add_order_array'] = $erlink;
}

My eyes need to be checked or start exercising my fat fingers.


Instruct ICC wrote:
 Wow this formatted badly.  (new hotmail on Safari -- MS made FF not even 
 render well)
 
 Anyway, are you sure you are reaching the code you want to reach?
 Perhaps !== is overkill and maybe even wrong when you should use ==.
 
 Same with the other === usage?
 
 Try some
 echo HERE1\n;
 echo HERE2\n;
 to see if you are getting to the line you expect.  Like after that count(~) 
 !== .
 
 _
 Gear up for Halo® 3 with free downloads and an exclusive offer. It’s our way 
 of saying thanks for using Windows Live™.
 http://gethalo3gear.com?ocid=SeptemberWLHalo3_WLHMTxt_2

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] disappearing array?

2007-09-20 Thread Jas
I am not sure what the heck is going with this but here is my problem.

I am trying to validate the contents of an array, then determine if the
errors are with the array or another form submitted variable.

The problem is after the code validates the array and other form
variables using an if statement, I then try to determine if the error is
in the array but for some reason the contents of the array disappear.

Weird. Any help is appreciated.

Here is the code:

function ValArray( $array )
 {
  echo pre; print_r( $array ); echo /pre;
  $val = new ValidateStrings();
  $data = 0;
  if( count( $array ) !== 0 ) {
   for( $x = 0; $x  count( $array ); $x++ ) { echo DATA:  .
$array[$x][0] . br;
if( $val-ValidateInteger( $array[$x][0] ) === -1 ) {// || (
$val-ValidateParagraph( $array[$x][1] ) === -1 ) || (
$val-ValidateMoney( $array[$x][2] ) === -1 ) || (
$val-ValidateAlphaChar( $array[$x][3] ) === -1 ) || (
$val-ValidateAlphaChar( $array[$x][4] ) === -1 ) ) {
 $data = -1;
}
   }
  } echo RESULTS:  . $data .  BR;
  return $data;
 }

if( ValArray( $_POST['add_order_items'] ) === -1 ) {
 $message = error;
 echo pre; print_r( $_POST['add_order_items'] ); echo /pre;

 // here is where it is empty or something else
 if( $fix-ValArray( $_POST['add_order_items'] === -1 ) ) {
  $errors['add_order_array'] = $erlink;
 }

 echo pre; print_r( $_POST['add_order_items'] ); echo /pre;

And the output:
Array
(
[1] = Array
(
[0] = ^%*(
[1] = ^*()
[2] = ^*()
[3] = ^*()_
[4] = ^%*()
)

[0] = Array
(
[0] = afadsf
[1] = adsfasfasdf
[2] = asdfasdfasdf
[3] = asdfasdfasdf
[4] = asdfasdfasdf
)

)

DATA: afadsf
DATA: ^%*(
RESULTS: -1

DATA:
RESULTS: -1

Array
(
[1] = Array
(
[0] = ^%*(
[1] = ^*()
[2] = ^*()
[3] = ^*()_
[4] = ^%*()
)

[0] = Array
(
[0] = afadsf
[1] = adsfasfasdf
[2] = asdfasdfasdf
[3] = asdfasdfasdf
[4] = asdfasdfasdf
)

)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] disappearing array?

2007-09-20 Thread Instruct ICC

Wow this formatted badly.  (new hotmail on Safari -- MS made FF not even render 
well)

Anyway, are you sure you are reaching the code you want to reach?
Perhaps !== is overkill and maybe even wrong when you should use ==.

Same with the other === usage?

Try some
echo HERE1\n;
echo HERE2\n;
to see if you are getting to the line you expect.  Like after that count(~) 
!== .

_
Gear up for Halo® 3 with free downloads and an exclusive offer. It’s our way of 
saying thanks for using Windows Live™.
http://gethalo3gear.com?ocid=SeptemberWLHalo3_WLHMTxt_2
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] disappearing array?

2007-09-20 Thread David Otton
On Thu, 20 Sep 2007 12:58:28 -0600, you wrote:

I am not sure what the heck is going with this but here is my problem.

I am trying to validate the contents of an array, then determine if the
errors are with the array or another form submitted variable.

The problem is after the code validates the array and other form
variables using an if statement, I then try to determine if the error is
in the array but for some reason the contents of the array disappear.

Weird. Any help is appreciated.

Very hard to suggest anything from the snippet presented, as it can't
be run without the supporting classes (ValidateStrings and whatever
$fix is supposed to be), and it won't parse; the // comment on the end
of line 9 borks it, and the if () on line 21 is missing its closing
brace.

If I assume one run-on if() statement and add the closing brace, I'd
say that this looks weird:

if( $fix-ValArray( $_POST['add_order_items'] === -1 ) )
{
$errors['add_order_array'] = $erlink;
}

In your snippet ValArray() appears to be a function, rather than a
method of $fix.

I suggest adding

error_reporting(E_ALL);

to the top of the script and letting us know what the output is, then
try to put together a minimal example that can actually be run (even
if you have to fake a ValidateStrings class that always returns -1)
and still shows your error.

Plus some general suggestions, feel free to ignore...

I think you're using || where you mean to use  in that run-on if()
statement. You're saying

IF (NOT Integer OR NOT Paragraph OR NOT Money)

which will always evaluate to true.

Unless your ValidateStrings class is holding some kind of state data
internally, it may be a good candidate for a static class.

ValidateStrings::ValidateParagraph()

is a bit verbose, how about just

Validate::Integer()
Validate::Paragraph()

etc.

In PHP, it's more typical to use true/false for success failure,
rather than returning -1 on failure, something like:

if (!Validate::Integer($value)  !Validate::Paragraph($value))
{
/* failure */
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php