dtbrd80422 2017-04-27 18:58
浏览 43
已采纳

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

As a result of discussion on my previous question:

Passing data to another page after form submit with 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. I get the unique ID by generating a random sequence in a function.

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.

  • 写回答

2条回答 默认 最新

  • duanchi0883649 2017-04-27 19:14
    关注

    $result is giving a null value because you're not returning anything from the function gen_uid(), you're only echoing things.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建