简体   繁体   English

将从函数调用中获取的数据传递到第二个PHP页面

[英]Passing Data taken from function call to second PHP Page

As a result of discussion on my previous question: 经过讨论我的上一个问题:

Passing data to another page after form submit with PHP 使用PHP提交表单后将数据传递到另一个页面

I've discovered my syntax is correct but not working the way I need it. 我发现我的语法是正确的,但是不能按我需要的方式工作。

I'm trying to pass a variable from my first page (my page with a form) to my second page (basically just a splash to say they submitted the form). 我正在尝试将变量从第一页(带有表单的页面)传递到第二页(基本上只是说他们提交了表单的飞溅)。

The variable is a unique ID used as a reference number for the submission. 该变量是用作提交参考编号的唯一ID。 I get the unique ID by generating a random sequence in a function. 我通过在函数中生成随机序列来获得唯一ID。

My problem is such: I can get my variable to pass across the two pages with this code 我的问题是这样的:我可以使用此代码让变量在两个页面之间传递

//(First Page)
$result = "TEST";
header('Location: submittedApplication.php?result='. $result);

and I grab it with this code 我用这段代码抓住了它

//(Second Page)
echo $_GET['result'];

Which works and passes a variable for me. 哪个有效,并为我传递了一个变量。 But what I need is to utilize this function: 但是我需要利用此功能:

    function gen_uid($l=10)
        { 
        $prefix = "#####";
        $str = ""; 
        date_default_timezone_set('America/New_York');
        $date = date("Y.m.d");

        for ($x=0;$x<$l;$x++)
        $str .= substr(str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 1);
        echo $prefix . $str . "<br/>" . "Generated On: " . $date; 
        }

What I would like to use is 我想用的是

$result = gen_uid();

But it just passes empty to the second page, even though when I echo it out to test on the first page it works and gives me data like this 但是它只是空着传递到第二页,即使当我在第一页上回显它以进行测试时,它仍然可以正常工作并为我提供了这样的数据

######NMB32R3MVQ
Generated On: 2017.04.27

As a recap; 回顾一下; Page 1 is: form.php , Page 2 is: submittedApplication.php , I'm trying to pass $result (while holding the string my function generates) from page 1 -> page 2. I'm new to web development so I'm open to any avenue of getting this to work, I'm just not able to determine what avenue that is. 第1页是:form.php的 ,第2页是:submittedApplication.php,我想通过$结果从页面(按住我的函数生成的字符串)1 - >第2页我新的Web开发,所以我我对开通任何可行的途径持开放态度,但我无法确定这是什么途径。

$result给出了一个空值,因为您没有从gen_uid()函数返回任何内容,而只是回声了。

Function you have created is not returning the desired result its just displaying it. 您创建的函数不会返回期望的结果,而只是显示它。 Replace: 更换:

echo $prefix . $str . "<br/>" . "Generated On: " . $date;

with

$final_result = $prefix . $str . "<br/>" . "Generated On: " . $date;
return $final_result; 

this should resolve your problem. 这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM