hi all...
im getting undefined index errors while running my code in localhost. im using wampserver 2.2...
but it works fine with older version of wampserver.
here is my example code for products page....

  <?php

            $man_id=$_GET['man_id'];
            $man_name2=$_GET['manf_name'];
            $man_name=str_replace('-',' ',$man_name2);
            $cat_id=$_GET['cat_id'];
            $cat_name2=$_GET['name'];
            $cat_name=  str_replace('-',' ',$cat_name2);

    if($cat_id!=""):
     ?>
    <span class="pro-head"><?php echo $cat_name;?></span>
    <?php  elseif($man_id!=""): ?>
    <span class="pro-head"><?php echo $man_name;?></span>
    <?php else:?>
    <span class="pro-head">Products</span>
    <?php endif;?>
    <?php 
    $search_text=$_GET['keyword'];
    $limit =10;$addLimit="";
                        if($_REQUEST['page']>0){
                            $page   = $_REQUEST['page'];
                            $offset = ($page-1)*$limit;
                        }else $page=1;

                        if($offset>0) $limitingVal[] = $offset;
                        $limitingVal[] = $limit;
                        if(count($limitingVal)>0) $addLimit = "LIMIT ".implode(",",$limitingVal);
                        //echo "hi".$addLimit;
    $param="";
    if($man_id!=""):    
            $sql="select SQL_CALC_FOUND_ROWS * from tbl_product WHERE manf_id='$man_id'  $addLimit";
        $man_name1= str_replace(' ','-',$man_name);

    $param = $param."man_id=$man_id&manf_name=$man_name1&";
    elseif($cat_id!=""):
    $sql="select SQL_CALC_FOUND_ROWS * from tbl_product WHERE cat_id='$cat_id' $addLimit";
    $cat_name1=str_replace(' ','-',$cat_name);
    $param = $param."cat_id=$cat_id&name=$cat_name1&";
    elseif($search_text!=""):
    $sql = "select A.*,B.cat_id from tbl_product A LEFT JOIN tbl_category B ON A.cat_id=B.cat_id where MATCH(A.search_title) AGAINST('$search_text' IN BOOLEAN MODE) OR A.prod_name LIKE '%$search_text%' OR A.prod_code LIKE '%$search_text%' OR B.cat_name LIKE '%$search_text%'  AND A.status='Y' $addLimit";
    else:
    $sql="select SQL_CALC_FOUND_ROWS * from tbl_product $addLimit";

    endif;
    $obj->query($sql);
    $nume=$obj->num_rows();
    //echo "hi".$nume;
                      if($nume>0){
                            $sqlTotlCnt="SELECT FOUND_ROWS() as total_rows";        
                            $resTotlCnt=mysql_query($sqlTotlCnt);
                            $totalNumRows = mysql_result($resTotlCnt, 0, 'total_rows'); 
                            $i=($page-1)*$limit;
    while($row=$obj->query_fetch()) {
    $i++;?>
    <ul>
    <li>
    <img src="uploaded_images/products/thumb/<?php echo $row['image_path'];?>" style="width:254px; height:150px"  />
    <span class="pro-name"><?php echo $row['prod_name'];?></span>
    <span class="pro-cat"><?php echo $row['short_desc'];?></span>

    <?php if($row['promo_price']!=0) {?>
    <span class="pro-amnt">Promo Price :$</span><h1><?php echo $row['promo_price'];?>*</h1>
    <?php } else{?>
    <span class="pro-amnt">Price :$</span><h1><?php echo $row['price'];?>*</h1>
    <?php }?>
    <a href="#"><img src="img/buynow.jpg" class="buy" /></a>
    <a href="#"><img src="img/addcart.jpg" class="buy" /></a>
    <a href="product_details.php?prod_id=<?php echo $row['prod_id'];?>&prod_name=<?php echo $row['prod_name'];?>"><img src="img/veiw-details.jpg" class="buy" /></a>
    </li>


    </ul>
    <?php
        //echo $row['prod_id'];
        //$imgpath=$row['image_path'];
    }

    ?>
    <div class="pagination">
    <?php //echo $totalNumRows."rows";

                            $total      =   $totalNumRows;
                            $pgng       =   $page;
                            $linktopage =   "products.php?".$param;
                            $maxperpage =   $limit;
                            include_once("includes/paging.php");
    }
    ?>

and it shows the errors like this...

SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: man_id in C:\wamp\www\aaaa\products.php on line 35
Call Stack
#   Time    Memory  Function    Location
1   0.0034  138720  {main}( )   ..\products.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: manf_name in C:\wamp\www\aaaa\products.php on line 36
Call Stack
#   Time    Memory  Function    Location
1   0.0034  138720  {main}( )   ..\products.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: cat_id in C:\wamp\www\aaaa\products.php on line 38
Call Stack
#   Time    Memory  Function    Location
1   0.0034  138720  {main}( )   ..\products.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: name in C:\wamp\www\aaaa\products.php on line 39
Call Stack
#   Time    Memory  Function    Location
1   0.0034  138720  {main}( )   ..\products.php:0

pls help me to solve this.... tnx in advnc....

try to check if $_GET['man_id'] is not empty or if $_GET is not empty or isset
like

if(isset($_GET) and !empty($_GET)){
    print_r($_GET);
}else{
    echo 'empty';
    exit;
}

befor this line $man_id=$_GET['man_id']; @ line 3

lets see whats the result

Hi,

You will need to add something like this

if(isset($_GET['param'])){

## rest of your codes here

}

else{

## code when $_GET is empty

}

The Theory!! Another trick I use outside the norms is this

if($_GET){


## codes here if $_GET is not empty
## make sure to check for empty values.

}
else{
## codes when $_GET is empty

}

Ok, ok,... I know people maybe wondering what the H.... is going on? why am I using it instead of (isset($_GET['param'].

Proof!

 if($_GET){

 var_dump($_GET); 

 ## codes above should return an array if $_GET is not empty

 }

Another way of doing this can be like this,

if($_SERVER['REQUEST_METHOD']=== $_GET){

## do things here

}
Member Avatar for LastMitch

@amiyar

im getting undefined index errors while running my code in localhost. im using wampserver 2.2...

Why are you are using shorthand php syntax? I don't see this often. What is the benefited of using shorthand php?

You know it would be easier for you if you just used what code739 or veedeoo examples.

Instead of this:

if():
//statements
elseif():
//statments
endif;

Change it to this:

if(){
//statements
}else{
//statements
};

@veedeoo,@code739.... tnx for helping me guys... i tried both tricks and it works fine....
@LastMitch.... tnx for ur suggestion... now onwards i will try to avoid shorthand php syntax.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.