Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters with `include`?

Tags:

php

I have a PHP script called customers.php that is passed a parameter via the URL, e.g.:

http://www.mysite,com/customers.php?employeeId=1

Inside my customers.php script, I pick up the parameter thus:

$employeeId = $_GET['employeeId'];

That works just fine. I also have an HTML file with a form that inputs the parameter, and runs another php script, viz:

<form method="post" action="listcustomers.php">
  Employee ID:&nbsp; <input name="employeeId" type="text"><br>
  <input type="submit" value="Show">
</form>

Then in my listcustomers.php script, I pick up the parameter so:

$employeeId = $_POST['employeeId'];

So far so good. But his is where I am stuck. I want to run my customers.php script, and pass it the parameter that I pave picked up in the form. I am sure this is really simple, but just cannot get it to work. I have tried:

include "customers.php?employeeId=$employeeId&password=password";

But that does not work. Nor does anything else that I have tried. Please help me.

like image 641
Philip Sheard Avatar asked Jul 24 '11 09:07

Philip Sheard


People also ask

What are the ways to pass parameters to and from procedure?

In the calling statement, follow the procedure name with parentheses. Inside the parentheses, put an argument list. Include an argument for each required parameter the procedure defines, and separate the arguments with commas.

Can we pass parameter in Get method?

Parameters can be passed in GET Request, if you are not sure how to do a GET Request using Postman, please take a look at the previous article How to make a GET Request. Since now you know how to make a GET request, we will move ahead with sending parameters in a GET request.

What does it mean to pass as a parameter?

Parameter passing involves passing input parameters into a module (a function in C and a function and procedure in Pascal) and receiving output parameters back from the module. For example a quadratic equation module requires three parameters to be passed to it, these would be a, b and c.


1 Answers

You can't add a query string (Something like ?x=yyy&vv=www) onto an include like that. Fortunately your includes have access to all the variables before them, so if $_GET['employeeId'] is defined before you call:

include 'customers.php';

Then customers.php will also have access to $_GET['employeeId'];

like image 193
Paul Avatar answered Oct 19 '22 16:10

Paul