isset/undefined issue

Links for php scripts

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Mon Jun 18, 2012 12:09 pm

isset/undefined issue

Postby thomachan » Mon Jun 18, 2012 12:20 pm

Hi, I'm really stuck on this and would appreciate an urgent response if possible. I'm getting this error message when i put the site live: Notice: Undefined variable: msg in E:\Domains\g\\user\htdocs\shoppingcart.php on line 197

The code is as follows:

Code: Select all

if(isset($_REQUEST['command']) && $_REQUEST['command']=='delete' && $_REQUEST['pid']>0){

   else if(isset($_REQUEST['command']) && $_REQUEST['command']=='clear'){
   else if(isset($_REQUEST['command']) && $_REQUEST['command']=='update'){
         if($q>0 && $q<=999){
            $msg='Some products not updated!, quantity must be a number between 1 and 999';


From what I know of php, the isset should stop the error message from displaying as there is no msg to display if the basket is populated. I'm still getting an error though and I'm tearing my hair out trying to find what I've got wrong.

Please help! Thanks :D

User avatar
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: isset/undefined issue

Postby egami » Tue Jun 19, 2012 8:36 am

Where are you calling the $msg variable?
From what I can see, you are only assigning the variable IF there is an error, which it would appear not to be likely if the user has > 0 and <= 999 items in a cart. If you want to mitigate this error, either assign it $msg = '' before adding any text to it, or do..

if (isset($msg)) {
echo '<span>'.$msg.'</span>';

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest