Jump to content

Recommended Posts

Posted

so I have an array (shipping) with a bunch of indexes. Such as name, address country etc.

I am able to debug and see whats in my array.

 

array

'firstName' => string 'Jordan' (length=6)

'lastName' => string 'Stern' (length=5)

'street1' => string '35 7th St Nw' (length=12)

'city' => string 'Bayamon' (length=7)

'province' => string 'choose' (length=6)

'province_hidden' => string '1' (length=1)

'country' => string 'choose' (length=6)

'country_hidden' => string '1' (length=1)

'zip' => string 'GY3 5HB' (length=7)

'phone' => string '4035291110' (length=10)

'business' => string 'Dev' (length=3)

'province_other' => string 'Puerto Rico' (length=11)

'country_other' => string 'Puerto Rico' (length=3)

 

I want to access 'country_other' so if a customer puts 'puetro rico' php can change it to usa.

 

I did this:

if (strtolower($this->post['shipping']['country_other']) == 'puerto rico') {

$this->post['shipping']['country_other'] = 'usa';

}

 

And it works when i debug:

 

array

'firstName' => string 'Jordan' (length=6)

'lastName' => string 'Stern' (length=5)

'street1' => string '35 7th St Nw' (length=12)

'city' => string 'Bayamon' (length=7)

'province' => string 'choose' (length=6)

'province_hidden' => string '1' (length=1)

'country' => string 'choose' (length=6)

'country_hidden' => string '1' (length=1)

'zip' => string 'GY3 5HB' (length=7)

'phone' => string '4035291110' (length=10)

'business' => string 'Dev' (length=3)

'province_other' => string 'Puerto Rico' (length=11)

'country_other' => string 'usa' (length=3)

 

But when I take my var_dump($this->post['shipping']) out, I get: "Undefined index: shipping in C:\dev\trunk\application\controllers\CheckoutController.php on line 972"

 

which is the same line as " if (strtolower($this->post['shipping']['country_other']) == 'puerto rico') {"

 

 

Any ideas?

Posted

Undefined index:

 

If I remember from my debugging days that's caused by an variable being empty.. most often caused when you try to write out content from let say a $_POST or $_GET that is empty.

 

So are you vardumping something that is depending on something being sent through a form or by other means to the script?

 

Add the isset() function to only assign the value from $_POST or $_GET if a value was sent, that should fix your problem.

 

example:

 

// of course you need to apply this to your code with the correct indexes etc. 

if( isset($_POST['send']) {

// the code that uses the $_POST 

}

Posted

This will be in your php settings.

 

You can hide these kind of errors, at the top of your php page put this code

 

<?

error_reporting(0);

ini_set('display_errors', '0');

?>

Posted

Do keep in mind though -- this just hides the error, it doesn't change the fact that there is an error.

 

True, but what he was seeing was just notices, not true errors. You are right though, it should be coded so that there isn't anything to report in the first place

Posted

If it were a personal site i was working on, maybe hiding the error would be acceptable. I am working full time for a company at the moment so Im sure i should be burying my bad code :P

 

I've got it sorted out, I actually changed the logic completely so I didnt have to start pulling and editing out of arrays.

 

Thanks!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...