0

First, I send the id to rec_update.php file like this:

location.href="http://localhost/pk/rec_update.php?id="+id;

On rec_update.php file, I access that value like this:

$id = $_GET['id'];

Now, I want to send this $id to rec_update1.php file. which can be called by clicking a button. On button I have applied a javascript function from where page will directs to rec_update1.php How do I get this value on another php file.

8
  • It depends your code. If you use objects, it is very simple to put it as a parameter of your call.... Commented Apr 15, 2016 at 12:31
  • I mean, you could just pass the GET variable to the next page again? Or even use sessions/cookies. Commented Apr 15, 2016 at 12:32
  • Try session variable Commented Apr 15, 2016 at 12:33
  • Why you don't use $_SESSION[] ? Commented Apr 15, 2016 at 12:33
  • It depends on your code. You also able to use ajax for passing data to another page. Commented Apr 15, 2016 at 12:36

2 Answers 2

1

HTML / HTTP is stateless, in other words, what you did / saw on the previous page, is completely disconnected with the current page. Except if you use something like sessions, cookies or GET / POST variables. Sessions and cookies are quite easy to use, with session being by far more secure than cookies. More secure, but not completely secure

.

Session:

<?php
//On page 1
$_SESSION['varname'] = $var_value;

//On page 2
$var_value = $_SESSION['varname'];
?>

Remember to run the session_start() statement on both these pages before you try to access the $_SESSION array, and also before any output is sent to the browser.

Sign up to request clarification or add additional context in comments.

Comments

1

In rec_update.php

<script>
    location.href="http://localhost/pk/rec_update1.php?id=<?php echo $id; ?>";
</script>

And in rec_update1.php

$id = $_GET['id'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.