In calculate.php I have this code:
//recovery the variables from an html form
$FirstNumber=$_POST['FirstNumber'];
$SecondNumber=$_POST['SecondNumber'];
$Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'.
//Now I have to call specific instructions in instructions.php (Which is the one for operations) sending to it my variables
//Now I have to recovery $result from instructions.php
echo "Result: $result";
Assume that in instructions.php I have this:
The page need to understand what instruction it have to do, in this case the ones from Operations sector
//-----Operations-------------------------------------------------------------------------
//recovery variables from calculate.php
//Tottaly doesen't know how
switch ($Operation){
case "+":
$result=$FirstNumber+$SecondNumber;
//Now I send the result in calculate.php
break;
//repeat for all the possible cases
}
//------Strings---------------------------------------------------------------------------
$control=$String;
if ($checked){
$control=$String."_Controlled";
//I have to return $control
}else {
$checked=true;
$control=$String."_Controlled";
//return $control
}
//------Other instructions for other requests---------------------------------------------
So, How can I "define" and call a series of instruction from another php page?
Please don't answer me with the "meta refresh" method, it's not what I'm looking for and what I asked.
You're having option to include
the page with all the function into current page using require_once or require method
now you can use the page where you are getting the variables in post method and include another page on the same page at the starting point for example,
if you are getting variables on calculate.php in post method then you can use require at the top of calculate.php
<?php
require('path/to/operation.php');
//recovery the variables from an html form
$FirstNumber=$_POST['FirstNumber'];
$SecondNumber=$_POST['SecondNumber'];
$Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'.
echo "Result: ". calculate($Operation, $FirstNumber, $SecondNumber);
?>
//In your Operation.php it should be like function, and you can call that function using calculate.php to get the result.
function calculate($Operation, $FirstNumber, $SecondNumber)
switch ($Operation){
case "+":
$result=$FirstNumber+$SecondNumber;
return $result;
break;
}
$control=$String;
if ($checked){
$control=$String."_Controlled";
//I have to return $control
}else {
$checked=true;
$control=$String."_Controlled";
//return $control
}
}
You can use include
file and can call the variable in operation.php
for example like below:
<?php
include('path/to/operation.php');
$result=$FirstNumber+$SecondNumber;
echo $result;
?>