Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

isset/undefined issue

Links for php scripts

Moderators: macek, egami, gesf

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\xxx.co.uk\user\htdocs\shoppingcart.php on line 197

The code is as follows:

Code: Select all
<?php
   include("includes/db.php");
   include("includes/functions.php");
   
if(isset($_REQUEST['command']) && $_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
      remove_product($_REQUEST['pid']);
   }

   else if(isset($_REQUEST['command']) && $_REQUEST['command']=='clear'){
      unset($_SESSION['cart']);
   }
   else if(isset($_REQUEST['command']) && $_REQUEST['command']=='update'){
      $max=count($_SESSION['cart']);
      for($i=0;$i<$max;$i++){
         $pid=$_SESSION['cart'][$i]['productid'];
         $q=intval($_REQUEST['product'.$pid]);
         if($q>0 && $q<=999){
            $_SESSION['cart'][$i]['qty']=$q;
         }
         else{
            $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
thomachan
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jun 18, 2012 12:09 pm

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>';
}
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.