在PHP中将函数传递给另一个页面

时间:2012-04-17 18:35:00

标签: php

所以这已经困扰了我一段时间了,我想把我存储在一个函数中的计算传递到另一个页面,我可以传递字段条目没有问题(对不起我在PHP新手)但是我如何通过我的计算从:

//计算部分(calculator.php) - 这是每个页面上的包含 计算是由每个页面上包含的用户条目进行的

// thank-you.php页面输出感谢评论并发送电子邮件 我收到所有其他信息很好,但功能将不会在我的电子邮件中通过。 计算的输出也存储在calculator.php中,这是包含但它输出到屏幕上的不是我的电子邮件:(。

我错过了什么吗?

抱歉(编辑)这是我的代码:

<?php
error_reporting(E_ALL);


if(isset($_POST['name']) && isset($_POST['to'])){

ini_set('date.timezone', 'Europe/Madrid');
$now = date("H:i");

$cutoff = "06:00";
$higherthan = "22:00";


    $name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$date = $_REQUEST['date'];
$returndate = $_REQUEST['returndate'];
$people = $_REQUEST['people'];
$return = $_REQUEST['return'];
$myemail = $_REQUEST['myemail'];

include_once('includes/config.php');

$settingsSql = mysql_query("SELECT * FROM transfers_in WHERE location='$to' AND no_passengers='$people'");
$settings        = mysql_fetch_assoc($settingsSql);

echo "From: ".$from." To: ".$settings['location']."<br />";
echo "Number of passengers: ".$settings['no_passengers']."<br />";

ini_set('date.timezone', 'Europe/Madrid');
$now = date("H:i");

$cutoff = "06:00";
$higherthan = "22:00";

echo "Time cost: ".$settings['price']." euros<br /><hr />Total: ";



    function timeCost() {

        $to = $_REQUEST['to'];
        $people = $_REQUEST['people'];
        $return = $_REQUEST['return'];

        include_once('includes/config.php');

        $settingsSql = mysql_query("SELECT * FROM transfers_in WHERE location='$to' AND no_passengers='$people'");
        $settings        = mysql_fetch_assoc($settingsSql);

        //echo $return;

        if ($return == "No"){
            if ((strtotime($now) < strtotime($cutoff)) || (strtotime($now) > strtotime($higherthan))){
                echo number_format($settings['price']) + 1.40;
            } else {
                echo number_format($settings['price']) + 0.00;
            }
        } elseif ($return == "Yes") {
            if ((strtotime($now) < strtotime($cutoff)) || (strtotime($now) > strtotime($higherthan))){
                echo number_format($settings['price']) * 2 + 1.40;
            } else {
                echo number_format($settings['price']) * 2 + 0.00;
            }
        }

        echo " in euros<br /><br />";   
    }

    echo timeCost();


} else { ?>

<form method="POST" action="thank-you.php" name="chooseDateForm" id="chooseDateForm">
            <label>Name:</label>
            <input type="text" value="" name="name" />

            <label>Telephone:</label>
            <input type="text" value="" name="telephone" />

            <label>Email:</label>
            <input type="text" value="" name="myemail" />

            <label>From:</label>
            <select name="from">
                <option selected="selected">Malaga</option>
            </select>
            <div class="clr"></div>

            <label>To:</label>
            <select name="to">

<?php foreach ($data as $place => $price){
    echo "<option>{$place}</option>\n";
}
echo '</select>
            <div class="clr"></div>

            <label>Date:</label>
            <input type="text" value="dd/mm/yyyy" id="date" name="date" class="date-pick" />
            <span id="calendar"></span>

            <div id="return-journey">
                <label>Return Date:</label>
                <input type="text" value="dd/mm/yyyy" id="returndate" name="returndate" class="date-pick" />
                <span id="calendar"></span>
            </div>

            <label>Number of people:</label>
            <select id="people" name="people">
                <option value="4">4</option>
                <option value="6">6</option>
                <option value="8">8</option>
            </select>
            <div class="clr"></div>

            <div id="return">
                <label>Is this a return<br />journey?</label>
                <div class="clr"></div>
                <div id="radio-buttons">
                    <input type="radio" name="return" value="Yes" class="radio returning" />Yes<br />
                    <input type="radio" name="return" value="No" class="radio" checked />No
                </div>
            </div>
            <div class="clr"></div>

            <input type="submit" name="submit" class="fauxButton" />            

        </form>';
}
?>

1 个答案:

答案 0 :(得分:5)

如果您正在使用会话,则可以将变量,结果,数组 - 存储到会话变量中,然后在新页面上检索它。

session_start();
$_SESSION['test_var'] = 'Jake';

然后当我导航到新页面并检索var:

    session_start();
echo $_SESSION['test_var'] 
    // outputs 'Jake'