James Daley
James Daley

Reputation: 289

include php file depending on which link is clicked?

I am trying to include several different php include files in my page attach.php which display 1 include file at a time depending on which link is clicked.

Here's my links:

 <a href="attach.php?tab=insurance"><div class="hewden_square"></div><h33>Insurance Documents</h33></a> 
 <a href="attach.php?tab=policy"><div class="hewden_square"></div><h33>Policy Documents</h33></a>  

next I have my php code which checks which link has been clicked.

    <?php
switch(isset($_GET['tab'])) { //switch is just like a bunch of if()s
    default: //default case
    case '': //default case
    include('include/attachments_overview.php'); //include page.html
    break;  //break, witch means stop
    case 'insurance': // page2, if changePage has the value of page2
    include('include/upload_insurance/upload_files.php'); //include page2.html
    break;  //break, witch means stop
    case 'policy': // page2, if changePage has the value of page2
    include('include/upload_policy/upload_files.php'); //include page2.html
    break; //stop it
} //end the switch
?> 

my default include file should be shown before any link is clicked and this is:

include('include/attachments_overview.php'); 

then one or the other should be included depending on which link is clicked. For some reason my default include file is shown as expected and my other include file

include('include/upload_insurance/upload_files.php'); 

is shown when I click the link attach.php?tab=insurance

however when I click on my last link attach.php?tab=policy this just seems to show the same include file for my insurance tab

include('include/upload_insurance/upload_files.php'); 

can someone please show me where I am going wrong or show me a better/more reliable way of doing this? Thanks

Upvotes: 0

Views: 1458

Answers (1)

Pinu
Pinu

Reputation: 412

<?php
$tb = isset($_GET['tab']) ? $_GET['tab'] : '';
switch($tb) { //switch is just like a bunch of if()s
    default: //default case
    include('include/attachments_overview.php'); //include page.html
    break;  //break, witch means stop
    case 'insurance': // page2, if changePage has the value of page2
    include('include/upload_insurance/upload_files.php'); //include page2.html
    break;  //break, witch means stop
    case 'policy': // page2, if changePage has the value of page2
    include('include/upload_policy/upload_files.php'); //include page2.html
    break; //stop it
} //end the switch
?> 

Upvotes: 1

Related Questions