943,683 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1774
  • PHP RSS
Oct 22nd, 2008
0

Passing Variables in Included File

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
yasmena is offline Offline
45 posts
since May 2008
Oct 22nd, 2008
0

Re: Passing Variables in Included File

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 C; Oct 22nd, 2008 at 8:36 am.
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Oct 22nd, 2008
0

Re: Passing Variables in Included File

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
Reputation Points: 10
Solved Threads: 0
Light Poster
yasmena is offline Offline
45 posts
since May 2008
Oct 22nd, 2008
0

Re: Passing Variables in Included File

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.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Oct 22nd, 2008
0

Re: Passing Variables in Included File

No its just basic Php , no files or functions
Reputation Points: 10
Solved Threads: 0
Light Poster
yasmena is offline Offline
45 posts
since May 2008
Oct 22nd, 2008
0

Re: Passing Variables in Included File

then post your required code......
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Oct 22nd, 2008
0

Re: Passing Variables in Included File

/*** 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
Reputation Points: 10
Solved Threads: 0
Light Poster
yasmena is offline Offline
45 posts
since May 2008
Oct 22nd, 2008
2

Re: Passing Variables in Included File

Try this in your switch statement:

php Syntax (Toggle Plain Text)
  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
jt1
Reputation Points: 13
Solved Threads: 3
Newbie Poster
jt1 is offline Offline
19 posts
since Aug 2007
Oct 23rd, 2008
0

Re: Passing Variables in Included File

Ur a HERO
that was so easy
THANKS "Jt1" SO SO SO MUCH
Last edited by yasmena; Oct 23rd, 2008 at 8:28 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
yasmena is offline Offline
45 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: session variables
Next Thread in PHP Forum Timeline: Problem with Signup Code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC