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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if check not working in an included file 1

Status
Not open for further replies.

amir4oracle

Programmer
Nov 3, 2004
46
CA
I have a file base.php, which is calling a file compose.php using:
include ('compose.php');

compose.php is a form with just two fields, which roughly as follows:

---------------------------------------
<?php
if (isset ($_POST['submit']))
{
// validation checks
// and database insertion
}
?>

<html><body>
.
.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

<input type="text" name="subj" value="<?php echo $_POST['subj']; ?>">

<input type="text" name="bdy" value="<?php echo $_POST['bdy']; ?>">

<input type="submit" value="Send" name="submit">

</form>
.
.
</body></html>
----------------------------------------

the thing is if i call compose.php separately using:

it works exactly as required, but when its called from base.php using the include or include_once or require or require_once functions, the if check as mentioned does not work so does not the rest of the php tagged part. Although the the form is displayed just fine.

What should I do to include compose.php and make it work as required. Your help is highly appreciated.
 
include and require both parse the file that they are "including", thus there is no fundamental reason why your code should not work.

you do not appear to have posted a portion of your code so we can't help with assessing other causes of the incorrect behaviour.

for the time being i'd suggest changing compose.php to be as follows:

Code:
<?php
  error_reporting(E_ALL);
  if (isset ($_POST['submit'])) 
  {
    echo "TEST PASSED";
  } else { echo "TEST FAILED <br/> ; print_r ($_POST); }
?>

<html><body>
.
.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

<input type="text" name="subj" value="<?php echo $_POST['subj']; ?>">

<input type="text" name="bdy"  value="<?php echo $_POST['bdy']; ?>">

<input type="submit" value="Send" name="submit">

</form>
.
.
</body></html>
and have a look at the results. there is an FAQ posted by sleipnir214 which contains other debugging techniques as well.

remember that if you include the file from base.php the $_SERVER['PHP_SELF'] variable will be base.php and not compose.php.
 
Thanks jpadie your last sentecnce worked:

remember that if you include the file from base.php the
$_SERVER['PHP_SELF'] variable will be base.php and not compose.php

I made it $_SERVER['compose.php'] and it worked.

But now the new problem is that if I call base.php from compose.php to go back using header():

header ("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/base.php?var=2");
exit();

It does not go back, how should I go back to base.php

Thanks in advance.
 
from your code you do not happear to have set the variable $_SERVER['compose.php'] thus you are likely to be outputting an empty string.

if you want to go back to base.php why not just put the relative or absolute path in by hand rather than trying to compute it with php?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top