?
Solved

PHP include

Posted on 2003-03-24
10
Medium Priority
?
225 Views
Last Modified: 2013-11-18
I am try to accept contents of a form having a same php page for display of the form and acceptance of the value with a if-else
This code works fine -
<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY bgColor=lightgoldenrodyellow >
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
     echo "in";
}else{
?>

<form name="test" action="try.php" method="post">
<TABLE cellSpacing=0 cellPadding=0 width="75%" border=0>
  <TR>
    <TD>Name</TD>
    <TD><INPUT name="name"><BR></TD>
    </TR>
  </TABLE></P>
<P>&nbsp;</P>
<input name=submit value=Send type=submit>
<input type="hidden" name="variables_of_form" value="name">
</form>
<?php
}
?>
</BODY>
</HTML>

But what i want to do is have a PHP include for the PHP code, something like this

<HTML>
<HEAD><TITLE>NJIT - Send Email</TITLE></HEAD>
<BODY bgColor=lightgoldenrodyellow >

<?php @include("one.php")?>

<form name="test" action="try.php" method="post">
<TABLE cellSpacing=0 cellPadding=0 width="75%" border=0>
  <TR>
    <TD>Name</TD>
    <TD><INPUT name="name"><BR></TD>
    </TR>
  </TABLE></P>
<P>&nbsp;</P>
<input name=submit value=Send type=submit>
<input type="hidden" name="variables_of_form" value="name">
</form>

<?php @include("two.php")?>

</BODY>
</HTML>

THIS is the contents of file "one.php"

<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
     echo "in";
}else{
?>

THIS is the contents of file "two.php"

<?php
}
?>


This is very straightforward but it is not working. Is there any other way out for a PHP include

Thank You
0
Comment
Question by:chopra_rr
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:VGR
ID: 8198170
of course it's not working.
The PHP files are parsed independently and must thus be syntactically correct.

Before searching for means (eval() and such) of doing what you want, i would ask THE question :

WHY do you want this ? Is this a GOOD reason ?
0
 

Author Comment

by:chopra_rr
ID: 8198251
I need to make many form and the action part(ie same code as one.php and two.php) is the same for all so i just entent to include these to files in the form file.
The example i hav provided is very trivial but the problem is specifically there.
Thank You
0
 
LVL 3

Accepted Solution

by:
wide_awake earned 100 total points
ID: 8198496
Why not reverse what you're trying to do?

i.e. have the main code include the appropriate content.

Then you'd have one PHP file that could include any html content you wanted to display, always using the same logic.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Expert Comment

by:VGR
ID: 8198660
exactly. Give him the points 8-)
Beware wide_awake, it's second time this evening that you "steal" an easy answer from me 8-)

beware, beware, my friend... :D
0
 

Author Comment

by:chopra_rr
ID: 8203522
That is a good idea but that wouldnt work in my case coz than i will hav to have new copies of the php code file with each html form file with php code including the html page.
I dont want that. i need a general php file i show before with a single copy n mutltiple copies of htm form page using that php code.
thank you
0
 
LVL 15

Assisted Solution

by:VGR
VGR earned 100 total points
ID: 8203633
not at all.

build ONE script (because your "php part is the same for all")

and use some parameter in its call, or a DB setting, or whatever, to deduce the index/filename of the HTML variable parts that you'll display here and then.

something like this :

<?
// session_start(); eventually
// includes enentually
// get the value of $theparameter, for example $_GET["theparameter"];
//
//
// here common PHP (functions) part to treat answers/actions on FORMs
//
// here common HTML code "before" variable part
// now issue the variable part
switch ($theparameter) {
 case 1 : include "first.html"; break;
 case 2 : include "second.html"; break;
 case 3 : include "third.html"; break;
  default : // do whatever
} // end switch;
// here common HTML code "after" variable part
?>

0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8203951
Now you've stolen *my* solution :P
0
 
LVL 15

Expert Comment

by:VGR
ID: 8203993
chacun son tour 8-)
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 11942538
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Split: wide_awake {http:#8198496} & VGR {http:#8203633}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

snoyes_jw
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question