When I tried to view this page, I was getting the following error.
Notice: Undefined variable: _SESSION in C:\wamp\www\wtchproject
\cart3.php on line 2
Notice: Undefined index: id in C:\wamp\www\wtchproject\cart3.php on
line 6
Then I did some googling and looked at some forums and codes and made the following changes to my code and now the error does not show.
The following is my new code.
I am not getting any error now but I have not fully understood what I have done. I will need to study a little more to understand the code fully. But I want to know whether have done the right thing. Am I going the right way?
Basically the key ‘id’ in the $_GET array was not defined. That is the undefined index error. The code checks if it is not defined, and if it isn’t then it sets it as null. So you no longer get this error before using it.
Also, $_SESSION appears to not be defined if you don’t start to session. session_start() starts up the users session and creates the $_SESSION variable. So if you don’t do session_start() then that variable is undefined.
Thanks. Just a small doubt. The tutorial that I am going through is supposed to be for beginners. Do you think there could be any reason for the author to leave out the bit of code containing session_start() and also for not defining the key ‘id’ in the $_GET array?
Maybe he was assuming session_start() was called earlier before the code you have is being used.
With the $_GET warning. It needs to be part of the url. For example on this forum thread ‘t’ is part of the url which equals the id of this topic. So you would need id=something in the url after a ?.
It isn’t much of a problem however, which is why he didn’t do the check. He probably has warning level errors turned off in his PHP installation so never realized these problems.