October 8, 2012

SubPaging Php with if else

Question by ElDiabl

I’m having a hard time passing values so here is the code:

These is the code to pass the values($vview is the container of the value) to be used when showing the sub page: from enrollalpha.php

   if(!empty($_POST['Vpanel'])){
             $vview = $_POST['Vpanel'];
             }else {
                 if(!empty($_GET['VPanel'])){                
                 $vview= $_GET['VPanel'];
                }else{
                 $vview= 'VS';
                }
             }

And this is the codes where $vview is to be used

if($vview == 'VS'){
            require_once 'vpanel_student.php';
        }
        else if($vview == 'VA'){
            require_once 'vpanel_adviser.php';
        }
        else if($vview == 'VA'){
            require_once 'vpanel_adviser.php';
        }else{
            require_once 'vpanel_student.php';
        }

let us assume my subpage now is showing vpanel_adviser.php at the said page i have this code:

    else if(empty($_GET['id'])){
               header("location:enrollalpha.php?&VPanel='VA'");

            }

So at enrollalpha.php remember i have this

    if(!empty($_GET['VPanel'])){                 
             $vview= $_GET['VPanel'];
            }else{
             $vview= 'VS';
            }

my current problem is when vpanel_adviser.php returns the user to enrollalpha.php it is not showing vpanel_adviser.php but shows vpanel_student.php Would appreciate any help on this.

Answer by Starx

You dont need to quote the value in the URL and unneeded “&” in the URI string.

header("location:enrollalpha.php?&VPanel='VA'");
                              // ^   &   ^ Here

Change to

header("location:enrollalpha.php?VPanel=VA");

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!