jstern Posted April 30, 2010 Report Share Posted April 30, 2010 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? Quote Link to comment Share on other sites More sharing options...
krillz Posted April 30, 2010 Report Share Posted April 30, 2010 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 } Quote Link to comment Share on other sites More sharing options...
abda53 Posted May 6, 2010 Report Share Posted May 6, 2010 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'); ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 6, 2010 Report Share Posted May 6, 2010 You can hide these kind of errors, at the top of your php page put this code Do keep in mind though -- this just hides the error, it doesn't change the fact that there is an error. Quote Link to comment Share on other sites More sharing options...
abda53 Posted May 6, 2010 Report Share Posted May 6, 2010 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 Quote Link to comment Share on other sites More sharing options...
jstern Posted May 6, 2010 Author Report Share Posted May 6, 2010 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 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.