can you tell me what is wrong with this code:
require( 'prepareOrder.php?oID='.$orders["id"].'');
Where: prepareOrder.php is a php located on the webpage root folder
and orders[id]
is an id from an sql database.
can you tell me what is wrong with this code:
require( 'prepareOrder.php?oID='.$orders["id"].'');
Where: prepareOrder.php is a php located on the webpage root folder
and orders[id]
is an id from an sql database.
In PHP, require()
is only getting the file name. This means if you require('somefile.php?somevar=somevalue');
this will check if a file called somefile.php?somevar=somevalue
exists. I "guess" you dont have this file with that name :)
So, if you need to pass parameters to an included file, you just need to declare those parameters before including the file.
Example: If you need to include somefile.php
and use $somevar
inside it, this is how to do it:
$somevar = 'somevalue';
include('somefile.php');
or
require('somefile.php');
and then you can use $somevar
inside somefile.php
without any problem :)
First of all no such file exists in your system having ? in name
All the variables declared before file include/require are available in that file and variables declared in included/required file are also available in parent file.
So simply include file and access variables as you access in other files ;)
You can't pass parameters when requiring or including a file. It is not executed as a web request, but simply included in the source - imagine copy and pasting the source code contents of the file, not the end result.
See the manual page for include()
.
PHP's require()
function does not accept GET
parameters as part of the request path.
As a result, PHP is looking for a file which is physically named prepareOrder.php?oID=1
(assuming $orders["id"]
= 1
)
You should, however, be able to access the $orders
array inside of your prepareOrder.php
file, so you can utilise the id
key within your required file.