learning
learning

Reputation: 25

is there a way to pass the value to another page?

in a.php I do:

$a = "hello,world";
$_POST['a'] = $a;

in b.php, i want to get $a value, when i echo $_POST['a'], there is no value output. how do i do?

Upvotes: 0

Views: 106

Answers (4)

Pankit Kapadia
Pankit Kapadia

Reputation: 1579

Page a.php:

<?php
session_start();
$a = "hello,world";
$_SESSION["name_anything"] = $a; // This will store $a value to the session
//here i've given session name "name_anything"
?>

Page b.php:

<?php
session_start(); //you need to initiate the session using this function
//You need to session_start() on every page on which you want to use session.
//Even on the page on which you are storing the session.
echo $_SESSION["name_anything"]; //this will print the value of $a
?>

Upvotes: 2

Peyman
Peyman

Reputation: 64

You can use $_SESSION[].

Here is an example:

$_SESSION['a'] = $a;

and use it in a.php

Upvotes: 2

samayo
samayo

Reputation: 16495

This would be the HTML form in a.php:

<form action="b.php" method="post" >
<input type="text" name="poster" />
<input type="submit" name="submit" />
</form>

In b.php, you can put some PHP to echo out the data

<?php

if(isset($_POST['submit'])){

echo $_POST['poster']; 


}

Upvotes: 1

James McDonnell
James McDonnell

Reputation: 3710

This is not how you post information to another page, you need to use a form for that, or another alternative is to use a GET request, or to use the session.

Try reading this, or other php articles. http://mrarrowhead.com/index.php?page=php_passing_variables.php

Upvotes: 1

Related Questions