?
Solved

PHP include

Posted on 2003-03-24
10
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
10 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logiā€¦
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

765 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