Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1304
  • Last Modified:

PHP calling one script from another

Hi,

I'm using the include statement to execute one PHP script from another, but I'm using smarty to separate HTML from PHP. The HTML is executed and the form posts back to the PHP file. The PHP code completes but does not return to the PHP script from which it was included.

What am I doing wrong?

Thanks,

Sean
0
rosemarybarry
Asked:
rosemarybarry
  • 3
  • 3
  • 2
  • +2
3 Solutions
 
nizsmoDeveloperCommented:
Are you able to post a short sample of the code for us to better understand?
0
 
DiscoNovaCommented:
What in the world do you mean by "The HTML is executed"? I'm acting as a distant echo to nizsmo: please do tell us more.
0
 
pstrawserCommented:
<? php include('filename.php') ?>

let say..    index.php, header.php, and footer.php

you cannot load  header.html  or footer.html  inside  <? php include('header.html') ?> , just rename the header.html to   header.php  and try again..

i hope that make since..  to make it short and sweet..    if the extension is .html and you are calling it to include("filename.html') it will not work.  just rename the filename.html to filename.php

anyway.. hope this help.. :)  
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
netmunkyCommented:
are you using include() or require()? they both handle a failure slightly different.

if there is an error in include(), the calling script will continue.
if there is an error in require(), it will kill the parent script with a fatal error.
0
 
rosemarybarryAuthor Commented:
Hi,

Yes of course. I didn't before because it would be overkill to include all my code. Here is the code relating to what I want to code.

UserSubmitJob.php

[CODE]
include( 'UserJobContactInfo.php' );
var_dump( $_POST );
[CODE]

UserJobContactInfo.php
[CODE]
if( !isset( $_POST['submitContactInfo'] ) )
{
    $selfChanged = "UserJobContactInfo.php";
    $smarty->assign( 'selfChanged', $selfChanged );
    $smarty->display('jobs/UserJobContactInfo.tpl');
}
else
{
      // Do lots of stuff here
      echo "Here";
}
[/CODE]

The include works and [CODE]UserJobContactInfo.php[/CODE] is executed. This script uses smarty to display a HTML form which when completed posts data back to [CODE]UserJobContactInfo.php[/CODE]. The comment do lots of stuff here replaces the processing on that data, which is not important here. The code completes and the echo is printed but execution doesn't return to [CODE]UserSubmitJob.php[/CODE] and the var_dump is never executed. Do I need an exit statement?

Hope this makes sense.

Thanks,

Sean
0
 
nizsmoDeveloperCommented:
Hi Sean

Thanks for posting the code, though we have to make sure of one thing, how are you sure that include("UserJobContactInfo.php"); finished executing? Any possibility of it throwing up an error or stopping execution for some reason?
0
 
rosemarybarryAuthor Commented:
No because it completes fine when I run it independently of the script that includes it. It successfully prints out "here" and the only code after that is closing braces. I want to be able to include the UserJobContactInfo.php so that it displays the HTML form using a smarty template. Goes back to UserJobContactInfo.php to process the data and then access that data through $_POST in the PHP script that included it.
0
 
netmunkyCommented:
well, to answer the one question, no you don't need exit();. that will definitely stop execution from going back to the calling script. in fact, i believe that and die() should be the only things that stop execution from going back to the calling script.
0
 
rosemarybarryAuthor Commented:
Of course yes, why is it not returning to the script that includes it?
0
 
DiscoNovaCommented:
Couple of suggestions:

1) before var_dump (but after include) do something else like "echo('We're here.');"
2) after the var_dump, do "flush();".

Reasoning:

1) Perhaps $_POST is not assigned? Or var_dump does not work... or something :)
2) You should always flush after you go :) Seriously, there might be some output buffering turned on

If neither of these help, do you have access to the servers error log. If you do, is there anything that might hint at a reason why this is happening.
0
 
nizsmoDeveloperCommented:
Yes print something BEFORE the includes, and something AFTER the includes, just to make sure everything is alright, maybe there's something wrong with var_dump? Either way you will know where the script got to if you echo something out.

Let us know how you get on.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now