Passing Variables in Included File

Thread Solved

Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Passing Variables in Included File

 
0
  #1
Oct 22nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Passing Variables in Included File

 
0
  #2
Oct 22nd, 2008
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'.
Last edited by Shanti Chepuru; Oct 22nd, 2008 at 8:36 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Re: Passing Variables in Included File

 
0
  #3
Oct 22nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Passing Variables in Included File

 
0
  #4
Oct 22nd, 2008
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.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Re: Passing Variables in Included File

 
0
  #5
Oct 22nd, 2008
No its just basic Php , no files or functions
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Passing Variables in Included File

 
0
  #6
Oct 22nd, 2008
then post your required code......
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Re: Passing Variables in Included File

 
0
  #7
Oct 22nd, 2008
/*** 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 19
Reputation: jt1 is an unknown quantity at this point 
Solved Threads: 3
jt1's Avatar
jt1 jt1 is offline Offline
Newbie Poster

Re: Passing Variables in Included File

 
2
  #8
Oct 22nd, 2008
Try this in your switch statement:

  1. switch ($action)
  2. {
  3.  
  4. case "partner_company":
  5. $_GET['page'] = 'partner'; // Define the page - variable will then be available in addcompany.php
  6. include ("../admin/addcompany.php");
  7.  
  8. break;
  9. }
Last edited by jt1; Oct 22nd, 2008 at 7:50 pm. Reason: typo
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

Re: Passing Variables in Included File

 
0
  #9
Oct 23rd, 2008
Ur a HERO
that was so easy
THANKS "Jt1" SO SO SO MUCH
Last edited by yasmena; Oct 23rd, 2008 at 8:28 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC