Skip to content
Advertisement

PHP pass variable received from form html to two php files

I’m new on php and I’m trying to get POST value from html and pass into two PHP files, where

  • First one execute query;
  • Second elaborate the query;

So the code html:

JavaScript

ExecSelect.php:

JavaScript

And select_querys.php is:

JavaScript

What I’m doing wrong?

Advertisement

Answer

You’re including this file at the top:

JavaScript

So it’s executing before any of this:

JavaScript

Thus none of that is defined when it’s executing. (The session hasn’t even been started yet at that time.)

Since the value is expected to be in the POST array, then in your select_querys.php you can simply read the value from $_POST['IdProduct'] just like you do in ExecSelect.php:

JavaScript

So you don’t even really need the use of session here, unless you plan on using that session value in future requests.

Just note that if you define the same variable (in this case $SS_IdProduct) in both files then when executing those files in the same context (as you do here) the second declaration of that variable will over-write any changes made to it previously. That’s not happening here, but something to be aware of as you continue to update your code.

(It’s also worth noting at this time that you’re not even using $SS_ProdSelect in select_querys.php, but I’ll assume that you plan to at some point.)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement