[Solved] Trying to change page content by menu clicks


In using php you can seperate your contents into files and include them selectively using if…else,include(‘fileName.php’) and checking for button click using isset(‘variableName’) pls note that the code below have not been tested :

    vars.php
    <?php

    $color="green";
    $fruit="apple";

    ?>

    test.php

    <form name="new user" method="post" action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> > 

    <input type="submit"  value="show"/>
    </form>
    <?php

if (isset($_POST["submit"])) {
include 'vars.php';    
 echo "A $color $fruit";
}else{  
    //code goes here
}

    ?>

Edit in light of your comment:

<ul>
                <li><a href="https://stackoverflow.com/questions/50437629/?link=1" name="link1">link 1</a></li>
                <li><a href="?link=2" name="link2">link 2</a></li>
                <li><a href="?link=3" name="link3">link 3</a></li>
                <li><a href="?link=4" name="link4">link 4</a></li>    
            </ul>

       <div id="mainSection">
            <?php
        $link=$_GET['link'];
        if ($link == '1'){
             include 'page1.php';
        }
        if ($link == '2'){
            include 'page2.php';
        }
        if ($link == '3'){
            include 'page3.php';
        }
        if ($link == '4'){
            include 'page4.php';
        }
            ?>  
        </div>

2

solved Trying to change page content by menu clicks