Q:

Undefined index: template_id

I am karthik, in my project i have one problem, i am getting error undefine index: template_id. I have searched more in net but i can't rectify this problem i have attached my code below, please guide me 
if($fetquery["template_id"] == 5){

                $query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");

                $fetquery = mysql_fetch_array($query);

             ?>

             <!-- Template5-->

             <input type="hidden" name="template5" value="template5">

    <div class="fillContent" id="subscreen5">    

    <div class="mainTitle"> 

            <h3>Fill Content - Template E</h3> 

        </div>

        <input type="hidden" name="template5id" value="<?php echo $fetquery['temp5_id']; ?>">

        <div class="current-title">  

            <label>Main Title</label> <input type="text" class="fillTitleText" name="etemp5title"placeholder="Lorem Ipsum" value="<?php echo $fetquery['title']; ?>"><!--  <a href="#">Edit</a>  -->

        </div>

        <div class="section2"> 

            <div class="contentSecTitle">

                <h3>Banner Image</h3>

            </div>

            <div class="subSec">                

                <div class="subSec1">  

                    <div class="contentSec2Left">

                                  <input type="text" id="template5banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">

             <div class="fileUpload btn btn-primary">

                 <span class="uploadImage"></span> 

                 <input id="temp5_bannerimg" onchange="addtemplate5banner(this)" name="etemplate5bannerimg" type="file" class="upload" value="Browse">

             </div>

                    </div>

                    <div class="contentSecRight"> 

                    <input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>">

                          <p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp5banner"><br><br>Current Image</p>

                         <!-- <p class="imageView4">filename.jpg</p>

                          <div class="deLete">

                                <a href="" onClick="removetemplate5banner()"></a>

                          </div> 
-->
                    </div>

                 </div>  

             </div> 

        </div>

        <div class="fillSec"> 

            <div class="contentSecTitle">

                <h3>Content</h3>

            </div> 

            <div class="current-textarea">  

                <div class="text-area">

                  <label>Description</label>  <textarea rows="4" name="etemp5desc" ><?php echo $fetquery['description']; ?></textarea>

                </div>

            </div> 

        </div> 

    </div>

    <?php 
}

    if($fetquery["template_id"] == 6){
        //echo "SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."";
        $query = mysql_query("SELECT * FROM ".$fetquery['table_name']." WHERE template_content_id = ".$fetquery['id']."");

        $fetquery = mysql_fetch_array($query);

     ?>

    <!-- Template6-->

    <input type="hidden" name="template6" value="template6">

    <div class="fillContent" id="subscreen6">    

    <div class="mainTitle">

            <h3>Fill Content - Template F</h3> 

        </div>

        <input type="hidden" name="template6id" value="<?php echo $fetquery['temp6_id']; ?>">

        <div class="current-title"> 

            <label>Main Title</label> <input value="<?php echo $fetquery['title']; ?>" type="text" class="fillTitleText" name="etemplate6title" placeholder="Lorem Ipsum">  <!--<a href="#">Edit</a>  -->

        </div>

        <div class="section2">  

            <div class="contentSecTitle">

                <h3>Banner Image</h3>

            </div>

            <div class="subSec">                

                <div class="subSec1">  

                    <div class="contentSec2Left">

                                  <input type="text" id="template6banner" value="<?php echo $fetquery['bannerimage']; ?>" class="upLoadText">

             <div class="fileUpload btn btn-primary">

                 <span class="uploadImage"></span> 

                 <input id="temp6_bannerimg" onchange="addtemplate6banner(this)" name="template6bannerimg" type="file" class="upload" value="Browse">

             </div>

                    </div>

                    <div class="contentSecRight">

                    <input type="hidden" name="gettopImage" value="<?php echo $fetquery['bannerimage']; ?>"> 

                          <p class="imageView3"><img src="<?php echo $fetquery['bannerimage']; ?>" style="width:82px; height:82px;" id="changetemp6banner"><br><br>Current Image</p>

                         <!-- <p class="imageView4">filename.jpg</p>

                          <div class="deLete">

                                <a href="" onClick="removetemplate6banner()"></a>

                          </div> -->

                    </div>

                 </div>  

             </div> 

        </div>

        <div class="fillSec"> 

            <div class="contentSecTitle">

                <h3>Content</h3>

            </div> 

            <div class="current-textarea">  

                <div class="text-area">

                   <label>Desription</label>  <textarea rows="4" name="temp6desc"><?php echo $fetquery['description']; ?></textarea>

                </div>

            </div> 

        </div> 

        </div>

        <?php } ?>

This code was in ajax page

A:

Try to add a check before using it. And also check if it is defined or not. - 
if (!empty($fetquery["template_id"]) && $fetquery["template_id"] == 5) { ...

