Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP DUPLICATE INCLUDE - how to get around?

Status
Not open for further replies.

jasc2k

Programmer
Nov 2, 2005
113
GB
I am using the index page as a header and then include any other pages within it using the previous code.
I also have a form page called signup.php. The form action is add.php and this file adds a user to a mysql database and if there are any errors its stored in a variable called $error
this file is basically this
Code: [Select]
if ($error == ""){
//then add user to database etc
else {
include("index.php");
I want it to include the signup.php with the errors on not the index page
but if i try to include("include/signup.php")
it appears but it not inside my index.php
my signup.php picks up the error using:
Code: [Select]
<?php echo "$error" ?>

so ideally I want to inclue("index.php?id=signup") but this errors as below:
Warning: include(index.php?id=signup) [function.include]: failed to open stream: No such file or directory in /web1/user3653/website/v3slider/add.php on line 163

Warning: include() [function.include]: Failed opening 'index.php?id=signup' for inclusion (include_path='.:') in /web1/user3653/website/v3slider/add.php on line 163

Any thoughts?
 
include and require use the file protocol unless you specify an alternative protocol.

the warning messages are being flagged because the file that you are trying to include do not exist at the location that you are looking for it.
 
Please read the fine manual. Paths in includes are not at all intuitive, even if they seem that way. Furthermore, an include is just an include. It has a somewhat separate scope, but you can pass any variable to it by using the $_GLOBALS array.

You can use an include as a function (you can use the return statement inside the included file and the include statement can therefore return a value, but you cannot pass parameters to that function.


+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Hi all, thanks for your replies I have added a ./ before the index.php?id=signup and that at least shows the page but the variable is lost I think I might need to find another full mysql login script...

Any sugestions?
Thanks
 
to provide the id you do the following
Code:
$id = 'signup';
include './index.php';
index.php then needs to look for the id in $id and not in $_GET['id'].

in the alternative redirect to the index file.

Code:
header('Location: index.php?id=signup');
exit();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top