So the fact that the message states: undefined index, this means or relates to a variable that is being used as an array and that it is that variable which has a "problem" where it is used.
Based on the line provided, this means that the "problem" is in the use of $_POST['telephone'].
So one asks, but what is the problem? Seems like it is reasonable to use.
Well, further the message: undefined index means that if the variable is in fact an array, that the particular array element is not defined (in php that is that it is not set or that the array key does not exist)... I just used two different "english" ways to "discuss" php evaluation functions. 1) isset($x['key1']), 2) array_key_exists('key2', $y)
So the thing is, before attempting to use an undefined index, need to either test if it is undefined or ensure that it is defined (likely through test and assignment).
There are a number of ways to work around this particular issue then. Selection of the desired method somewhat depends on what all is going on in the software and how many times some sort of "special" action needs to be taken.
If not mistaken for this "variable" ($telephone) it is defined this one time and the posted data is not needed any further.
So... I would consider performing a simple test as part of the assignment to $telephone. This is instead of ensuring that $_POST['telephone'] is assigned a value so that any use of that array index would exist.
So, in this case there is a little bit of a "complicated" action taken on the posted variable. Because of that, I would probably test for the array key (index) and if it is as desired then assign $telephone to that "complex" action, otherwise I would set it to some acceptable "empty" value. It could be an empty string, it could be null, it could be a zero (0), but I would determine what value based on how $telephone is used. Even in the "test" I described, one could use the tertiary conditional ( (test ? True-action : False-action) ) Or could use a basic if/else type structure or... as preferred for if/else assign the empty value, test if there is a value to be assigned and then instead assign the non-empty value expected...
But... all of that above also depends on why in the world this variable is being set when there is no data posted for the variable. Is this occurring when the page is first loaded? Is this occurring because the field is not being displayed on the form and when the form is being submitted? Could that line be put inside some other "tested" area so that the assignment is only made/tried when it is confirmed that posted data should be present? Did something before this line unset the variable causing this problem?
These questions are just to suggest ways that could have led to this line being an issue and maybe some sort of solution direction...
What I did in order to learn about php troubleshooting was to search the base of those error messages using my favorite search engine. Its not zen cart specific, its php... I then looked at several different common occurrences and potential solutions. I also on occasion (call me weird if you like) will just read code to see how something works, why it is written that way, look at possible problems or ways to cause one, and then look for commonalities of how the teams has suggested to address those issues...
Just some ideas and considerations. Hopefully helps in your venture of learning. Also consider using the developers tool kit to help find things within the code, the database, etc...


Reply With Quote
roductsID', $_GET['pID'], 'integer');
