473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calling one PHP script from another

69
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
Oct 10 '07 #1
5 3505
Atli
5,058 Expert 4TB
Hi Sean.

The include() function inserts the PHP code from the file you specify into the current code. So if the file you include has has an exit() or header() function which causes the code to stop executing or causes the page to be redirected, the rest of the original code, after the include() function will never get executed.

Could you post the code that is causing the problem? It may help us understand exactly what is going on.
Oct 10 '07 #2
Sebarry
69
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

Expand|Select|Wrap|Line Numbers
  1. include( 'UserJobContactInfo.php' );
  2. var_dump( $_POST );
  3.  
UserJobContactInfo.php
Expand|Select|Wrap|Line Numbers
  1. if( !isset( $_POST['submitContactInfo'] ) )
  2. {
  3.     $selfChanged = "UserJobContactInfo.php";
  4.     $smarty->assign( 'selfChanged', $selfChanged );
  5.     $smarty->display('jobs/UserJobContactInfo.tpl');
  6. }
  7. else
  8. {
  9.       // Do lots of stuff here
  10.       echo "Here";
  11. }
  12.  
The include works and
Expand|Select|Wrap|Line Numbers
  1. UserJobContactInfo.php
is executed. This script uses smarty to display a HTML form which when completed posts data back to
Expand|Select|Wrap|Line Numbers
  1. UserJobContactInfo.php
. 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
Expand|Select|Wrap|Line Numbers
  1. UserSubmitJob.php
and the var_dump is never executed. Do I need an exit statement?

Hope this makes sense.

Thanks,

Sean
Oct 10 '07 #3
Atli
5,058 Expert 4TB
Ok, I see.

I think the problem is that you are posting the form data to 'UserJobContactInfo.php' rather than 'UserSubmitJob.php'.

When the form is submitted, it redirects the browser, calling 'UserJobContactInfo.php', bypassing the include() in 'UserSubmitJob.php' and going straight to 'UserJobContactInfo.php'. So the var_dump() function is called when the form is printed, there is simply nothing to print.

Try changing the form, having it submit it's data to 'UserSubmitJob.php' instead of 'UserJobContactInfo.php'.
Oct 10 '07 #4
Sebarry
69
Hi,

Yes I could change the form action in the smarty template for 'UserJobContactInfo.php' to 'UserSubmitJob.php' but that would mean copying the form processing data from UserJobContactInfo.php which is a script that I want to reuse.

By not changing the HTML form it posts to UserSubmitJob.php. By changing it posts to UserJobContactInfo.php which is what I want but UserJobContactInfo.php appears to complete. Printing the string here but doesn't go back to UserSubmitJob.php from which it was included.

Sean

Ok, I see.

I think the problem is that you are posting the form data to 'UserJobContactInfo.php' rather than 'UserSubmitJob.php'.

When the form is submitted, it redirects the browser, calling 'UserJobContactInfo.php', bypassing the include() in 'UserSubmitJob.php' and going straight to 'UserJobContactInfo.php'. So the var_dump() function is called when the form is printed, there is simply nothing to print.

Try changing the form, having it submit it's data to 'UserSubmitJob.php' instead of 'UserJobContactInfo.php'.
Oct 10 '07 #5
Atli
5,058 Expert 4TB
Hi,

Yes I could change the form action in the smarty template for 'UserJobContactInfo.php' to 'UserSubmitJob.php' but that would mean copying the form processing data from UserJobContactInfo.php which is a script that I want to reuse.

By not changing the HTML form it posts to UserSubmitJob.php. By changing it posts to UserJobContactInfo.php which is what I want but UserJobContactInfo.php appears to complete. Printing the string here but doesn't go back to UserSubmitJob.php from which it was included.

Sean
OK. This is getting a little confusing...

When you submit a form, your browser is redirected, creating an entirely new Request. Your include, which was created in the previous request, is thrown away, forgotten.

You can submit your form to the 'UserSubmitJob.php' without changing a thing in your code. It will include the 'UserJobContactInfo.php' and run the form processing code that you put there. (This is all based on the code you posted, of course)

The include() function imports the code of the file you specify into the current code and executes it.

And by the time you see anything in your browser, all the PHP code has been executed. What happens after you post your form has nothing to do with the code executed before it was shown.
Oct 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
2
by: Shailan | last post by:
Hi Im having trouble with the following code that seems to be behave differently when called from the browser as opposed to the command line. The calling script is a cgi that forks, with the...
14
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild....
14
by: Mark C. | last post by:
I'm trying to call a batch file that I've built using the FileSystemObject and CreateObject("Wscript.Shell"), oShell.Run... in an asp script. Naturally, I can get the script to work from a command...
8
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js...
1
by: Stefan Barlow | last post by:
I have a mechanism that performs a server transfer to another page that uses the same codebehind class if an alternate page URL exists in the application variables. My problem is there is an...
13
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
5
by: Newbie Coder | last post by:
Hello all I have 3 functions in a javacrip file (MyScript.js), which is added to an ASP.NET 2.0 project 1) no right-click 2) no select text (copy...) 3) History.Back()' How do I call...
9
by: Catherine Moroney | last post by:
I have one script (Match1) that calls a Fortran executable as a sub-process, and I want to write another script (Match4) that spawns off several instances of Match1 in parallel and then waits...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.