0

I'm having a brain fart and as dumb/easy as it probably is I can't seem to figure it out and it's really starting to annoy me.

I'm getting 2 errors that are both the same:

Notice: Undefined variable: source in D:\xampp\htdocs\DB\users.php on line 24

This is my users.php:

<?php include('header.php'); ?>


<!-- Main content -->
<section class="content container-fluid">

    <?php

        getSource();
        
        switch($source){
                
            case 'add_user'; //Error here line 24
                
                include "includes/page/add_user.php";
                
            break;
                
            case 'edit_user';  //same error here line 30
                
                include "includes/page/edit_user.php";
                    
            break;
                
            default:
                
                include "includes/page/view_all_users.php";
                
            break;
                
        }
    ?>


</section>
<!-- /.content -->


<?php include('footer.php'); ?>

This is my function:

function getSource(){
    
    if(isset($_GET['source'])){
        
        $source = $_GET['source'];
        
    } else {
        
        $source = '';
        
    }
    
}

My View_all_users page just has a table displaying all users in database, and my other two pages are empty

Riley
  • 153
  • 3
  • 3
  • 13
  • You have a semi colon ; on the end of the case statements, they need to be full colons :, i.e. case 'add_user': – dougtesting.net Aug 11 '17 at 02:44
  • Try using in this way; case "add_user": in line 24 & case"edit_user": in line 30 use full colons instead of semicolon. – Suresh Sapkota Aug 11 '17 at 02:51
  • @SureshSapkota i tried it that way, it still gives me an undefined variable error. It has something to do the function and passing the variable across a webpage itself i just can't figure out how to fix it – Riley Aug 11 '17 at 02:57
  • will you initializing your variable $source = ""; in your function before checking it. – Suresh Sapkota Aug 11 '17 at 03:09

0 Answers0