Jump to content

Undefined Variable


bomberman

Recommended Posts

Why does php show undefined variable? I researched and found out that if the variables aren't set then they will likely show undefined variable. However, I used the isset function to check if the variable is undefined and if it is then set it to $varaible ="" . That didn't work and then later i tried $variable =  NULL. What should I do Can you please see the code and tell me what shall i do. Thanks a million 

<?php require_once("includes/connection.php")?>
<?php require_once("includes/function.php") ?> 
<?php require_once("includes/header.php") ?>
<?php
    if(isset($_GET['subj'])){
        $sel_subj = NULL;
        $sel_subj = $_GET['subj'];
   
    } elseif (isset($_GET['page'])){
        $sel_page = NULL; 
        $sel_page = $_GET['page'] ;
        
    } else {
        $sel_subj= NULL;
        $sel_page =NULL; 
    }
?>

    <table id = "structure" >
        <tr> 
            <td id = "navigation" >
                <ul class= "subjects" > 
            <?php
                $subject_set = get_all_subjects();
                while ($subject = mysql_fetch_array($subject_set)){ // <a href = "content.php?subj=1" >
                    if ($sel_subj == $subject["id"]){
                        echo "<li class = \"selected\" ";
                    }else{
                        echo "<li> ";
                    }
                    "<a href = \"content.php?subj=" . urlencode($subject["id"]) . "\">" . $subject["menu_name"]. "</a></li>" ;
                    
                    
                    $page_set = get_pages_for_subjects( $subject["id"] ) ; 
                    echo " <ul class = \"pages\"> ";
                    while ($page = mysql_fetch_array($page_set)){
                        echo "<li><a href = \"content.php?page=" . urlencode($page["id"]) . "\">" . $page["menu_name"] . "</a></li>" ; 
                    }
                    echo "</ul>" ; 
                }
            
            ?>
                </ul>
            </td>
            
            <td id= "page" >
                <h1> Main Area To Get Your Information </h1>
                <?php echo $sel_subj ; ?> <br/>
                <?php echo $sel_page ; ?> <br/> 
                
            </td>    
        </tr>
    </table>
<?php include ("includes/footer.php") ?> 

The variable im refering to is $sel_subj and $sel_page at the top of the code. Here is an attachment of the error 

post-168980-0-52509200-1400711034_thumb.png

Edited by bomberman
Link to comment
Share on other sites

My logic says to me,

<?php
    if(isset($_GET['subj'])){
        $sel_subj = NULL; // to $sel_page = NULL; 
        $sel_subj = $_GET['subj'];
   
    } elseif (isset($_GET['page'])){
        $sel_page = NULL;  //to $sel_subj = NULL;
        $sel_page = $_GET['page'] ;
        
    } else {
        $sel_subj= NULL;
        $sel_page =NULL; 
    }
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.