Kapil Garg
Kapil Garg

Reputation: 173

how to send php variable to another php page?

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.

Upvotes: 0

Views: 1424

Answers (2)

Adersh
Adersh

Reputation: 598

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'];

Upvotes: 1

Samir Sheikh
Samir Sheikh

Reputation: 2401

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.

Upvotes: 1

Related Questions