Is It Possible to pass a variable through an included file

include("../admin/addcustomer.php?page=partner");

i tried it but it says : Failed to open stream: No such file or directory

plz i need help and if it's not possible how can i pass this variable

Recommended Answers

All 8 Replies

I think we don't need to pass a variable to an included file, it already has
access to all variables in the including script. It becomes part of the
script that is including it.

$page = 'partner';
include '../admin/addcustomer.php';

Now addcustomer.php will see that $page contains 'partner'.

No,Thats not the case in my script
i have a file called links this file contains a switch statement and i need to send this variable to that file addcustomer
i also tried your way but it not working
the file didnt recognize that page variable

Is the included file just basic PHP, or does it have classes/functions in it, if the file uses functions you may need to register the variable as a global variable within each function you want to use it in.

Otherwise, post up your code so we can see what you are doing.

No its just basic Php , no files or functions

then post your required code......

/***  The Links script called adminlinks.php***/
   <?session_start();

$action=$_GET['action'] ;

switch ($action) {

case "partner_company":

  include ("../admin/addcompany.php?page=partner");

    break;

 /********** The AddCompanyScript *********/
   <?session_start();
if($_SESSION['utype']!='admin')
    header("location:login.php");

if(!empty($_GET['page']))
   $flag=1;
        else $flag=0;
  /******   Index2.php***********/
      if($_SESSION['utype']=='admin')

            {<? include("includes/adminlinks.php") ;?> }

 /***********AddPartner Script******/
  <?session_start();
if($_SESSION['utype']!='admin')
    header("location:login.php");

$value=$_POST['radio_value'];
   if($value=="company")
         {

           header("Location:index2.php?action=partner_company");

         }

/**********************/

I know this is a little bit complicated But Here the Storyboard ::)
i got a table called partners by which the admin can add a partner ..this partner can be an individual or can be a company ..so i made the admin choose before adding whether he wants to add a partner or a partner_company so if the last was the case he should be directed to the addcompany script BUT with a variable called page=partner

Try this in your switch statement:

switch ($action)
{

	case "partner_company":
	$_GET['page'] = 'partner'; // Define the page - variable will then be available in addcompany.php
	include ("../admin/addcompany.php");
	
	break;
}
commented: Good teaching others...keep it up... +2

Ur a HERO
that was so easy
THANKS "Jt1" SO SO SO MUCH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.