珀尔 |第二次提交后没有得到值

PERL | Not getting the value after second submit

大家。

我正在用 Perl 做一个工具,它实际上验证数据库中的状态,如果有必要,它会得到正确的查询,并在确认后更新值。

该页面可能包含三种内容:

如果将要使用的查询已填满,它会更新并 returns 状态。

如果只有用户输入的序列号,它会生成查询,然后要求确认。

如果这 2 个变量中的 none 已经填写,它将转到用户可以提交序列号的主表单。

我面临的问题是,在它生成 $final_query 并显示确认后,当我单击“确认”按钮时,它会重新加载页面,但它直接通过 if($final_query)甚至验证 $serial_no 是否已设置的 elseif

如果我执行第二次提交,Perl 真的会丢失这些值吗?还是我做错了什么?

我很想得到一些解释,因为这是我第二次用这种语言做事。

提前致谢!

--编辑

我截断了代码以显示它定义 $final_query 的位置,但我保留了结构以帮助理解。

完整代码可在 http://pastebin.com/6NqhbVau

#headers
if ($final_query) {

        $content = "<h1>first if</h1>";
#updateESNDatabase($database, $final_query);

#it only enters here if the user type the ESN
}elsif ($serial_no) {
        #selects the database
            switch(checkUpdateNeeded($database, $serial_no)) {
                case 0 {
            #Shows that the updates are no needed
                }
                case 1 {
                    $final_query = `cat $query1`;
                    chop($final_query);
                    $final_query =~ s/SERIALNUM/$serial_no/g;
                    $final_query =~ s/LOGINID/$login_id/g;
                    $content = $cgi->start_form .
                    "<center>" .
                        "<h3> Please double check the queries below before you update on database </h3>" .
                    "</center>" . 
                    $cgi->submit("Confirm") . $cgi->end_form;

                    $content .= $final_query;

                }
                case 2 {
                    #Makes almost the same as the first case, it only uses a different file to generate the query.
                }
            }
} else {
    #Generates the first page, where the users inputs information
} 
$page->set_content($content);
$page->process;

我想出了如何执行此操作。 根据我的分析,我不能简单地创建一个变量并通过 cgi 形式传递它。

为了解决这个问题,我所做的是在 HTML 中创建一个隐藏输入,然后通过它发送变量。

<input type='hidden' name='the_query' value=\"$final_query\">