in reply to Re: Losing session value
in thread Lossing session value

No, that didn't work! Even removing the check for empty value my $got_file_name = $cgi->param( 'doc_upload' ); from the code I am still losing the session value.

Replies are listed 'Best First'.
Re^3: Losing session value
by hippo (Archbishop) on Dec 13, 2017 at 16:59 UTC

    You are not checking for an empty value, you are setting one. And if you don't do that, you are setting it to undef which is just as bad. Here is what I think you should be doing:

    my $got_file_name = $cgi->param( 'doc_upload' ); # Store file name to use later but only if it is defined. $session->param("doc_uploaded", $got_file_name) if $got_file_name; my $filename_uploaded = $session->param("doc_uploaded");
      Still a mystery, it doesn't work, I can't get the value from the session!

        So, here's an SSCCE which works well.

        #!/usr/bin/perl use strict; use warnings; use CGI::Session; my $session = CGI::Session->new or die CGI::Session->errstr; my $cgi = $session->query; my $html = '<h1>Session test</h1>'; my $field = 'doc_upload'; # Initial value my $gfn = $session->param ($field); $html .= $gfn ? "<p>Initial value: $gfn</p>" : '<p>No iniital value</p +>'; # New value my $newgfn = $cgi->param ($field); $html .= $newgfn ? "<p>Supplied value: $newgfn</p>" : '<p>No supplied value</ +p>'; if ($newgfn) { $session->param ($field, $newgfn); $html .= '<p>Initial value overwritten with new value</p>'; } $html .= qq{<form method="post"><input type="text" name="$field"/> <input type="submit" value="Submit new value"/></form>}; print $session->header, $html; $session->flush;

        The HTML is minimalistic but serves the purpose. Run this CGI a few times to convince yourself that it is indeed storing new values but only when supplied. Then see how this differs from your script and amend yours accordingly. Good luck.