Problem with html form & session??

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
TheWebExpert
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 25, 2019 3:09 pm

Thu Apr 25, 2019 3:14 pm

<form name="exampleForm1" onsubmit="popup(this)" action="askdel03.php" method="post" style="z-index: 1; width: 261px; height: 148px; position: absolute; top: 32px; left: 17px">
<input type=image alt=Submit id="yy" src="../Images/Database/Button_Select_1.png" width="136px" height="50px" style="z-index: 1; position: absolute; top: 16px; left: 269px; right: -120px;" onmouseover="this.style.cursor='hand'; SetImage('yy','../Images/Database/Button_Select_2.png'); return false;" onmouseout="SetImage('yy','../Images/Database/Button_Select_1.png'); return false;" border="0" />
<input type="hidden" name="img" value="<? echo $img; ?>" />
</form>

This form pops up a window with a simple "yes"/"no" question about deleting the record.

<form action="process_delimage.php" method="post" enctype="multipart/form-data" style="width: 140px; height: 23px; position: absolute; top: 238px; left: 83px">
<input type="hidden" name="img" value="<? echo $img ?>" />
<input type="image" alt="Submit" id="yy" src="../Images/Button_Yes_1.png" width="140" height="23px" style="z-index: 1; position: absolute; top: 0px; left: 0x" onmouseover="this.style.cursor='hand'; SetImage('yy','../Images/Button_Yes_2.png'); return false;" onmouseout="SetImage('yy','../Images/Button_Yes_1.png'); return false;" border="0" />
</form>

For some strange reason, though, when I click the "yes" button in the 2nd form, instead of going to the "process_delimage.php" like it should, it's loading the login page. I tried a completely different page in the same file, but it did the same thing. Am I losing my session variable when I do the popup? Or is there a different reason it's going to the login page?

chorn
php-forum Fan User
php-forum Fan User
Posts: 601
Joined: Fri Apr 01, 2016 2:18 am

Thu Apr 25, 2019 10:08 pm

Have a look at your webdevelopers console first. Are you beeing redirected? Then look at the part of your script that is redirecting. Use var_dump() to view alle variables involved.

TheWebExpert
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 25, 2019 3:09 pm

Fri Apr 26, 2019 10:29 am

I dumped out all the variables using get_defined_vars() - var_dump() didn't do anything at all. All the variables are there, and they're all correctly named and with the correct data. I have no idea how to check to see the webdevelopers console is redirecting me.

The (improper) redirection only seems to be happening with this popup. I'm wondering if there's a problem in the code itself, as a difference between PHP v5.x and version 7.2, which is what the host is running. I've been upgrading this code to the 7.2 standard ever since I started this project, but there may be some coding issues I haven't yet found.

TheWebExpert
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 25, 2019 3:09 pm

Fri Apr 26, 2019 10:47 am

Oddly enough, the $_SESSION variable wasn't getting carried over from the popup window. It was set INSIDE the popup, but not once the popup did its form posting to the process_delimage.php code. It somehow got lost. What I did to fix this was to put a hidden variable inside the code which was popped up to pass along the $_SESSION variable inside the post. Then, in the session.php code, I check to see if the $_SESSION variable is less than 1 in length; if so, it then assigns the $_POST variable which contains the proper info.

Problem solved.

Why does this happen? That's the primary question. Since the $_SESSION variable was set BEFORE the popup, and IN the popup, why is it not present when the process_delimage.php includes the session.php code? I wonder if maybe this is due to the fact that the popup window has its own "session," so to speak, and that's why it's not seeing it.

Anyway, thanks for the help!

Post Reply