0

Let's all be examples.
I am redirecting from A.php to B.php with a parameter, let's say it ID=1.
Therefore,

..../B.php?ID=1

And I wanna hold the value of the ID.
Whenever I press a button on B.php, the value ID=1 gone.

Any idea of how can I hold that value ?
Thanks for in advance.

2
Contributors
6
Replies
32
Views
5 Months
Discussion Span
Last Post by gahhon
0

Whenever I press a button on B.php, the value ID=1 gone.

Can you clarify this? Right now it seems the issue is not related to A.php but just to what happens inside B.php.

0

Yes.
When page load of B.php, I store the value of the URL.

$id = $_GET['cust_no'];

Then whenever I pressed a button on B.php, the value $id become null.

I would like to keep the value of $id after B.php is submit.

0

I already try using Session to retrieve the value.
But the value of session still null.

A.php

<?php
    function runProrgam() {
        session_start();
        $_SESSION["custno"] = $_GET["cno"];
        ECHO ("<script type='text/javascript'>");
        ECHO ("document.location.href = 'B.php'");
        ECHO ("</script>");
    }

    runProgram();
?>

B.php

    <?php
        function runProrgam() {
             session_start();
             $custno = $_SESSION["custno"];

             ECHO ("This is Session Value " .$custno);
        }
        runProgram();
     ?>
0

Please also note that my session_start() very top of every pages before HTML and php code

<?php session_start(); ?>
HTML
ANOTHER PHP CODE BEHIND

2

Hmm, the session in this case it is not, probably, the best approach: what happens if, in the current session, you open multiple tabs of A.php with different IDs?

A.php?id=123
A.php?id=124
A.php?id=125
...

It would screw up, because the session value would be rewritten by the latest loaded tab. Append the query string to B.php, so if you are using a form you can do:

<form method="get" action="B.php?id=123">

Or hide it in the input fields:

<input type="hidden" name="id" value="123">

If you want more appropriated help, share an example of what you are trying to do.

Votes + Comments
Good shout about multiple tabs +1 - a common gotcha!
1

Thanks for your help.
Now I am enable to execute my program correctly with applied hidden field.
So when 2nd page load, I'll store the URL value into hidden value.

<input type="hidden" name="cno" value="<?php ECHO ($_GET["custno"]); ?>" />

Then whenever a button pressed on 2nd page, I am able to retrieve the value of it.

ECHO ($_GET["cno"]);

Thanks for your help buddy.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.