lanlee
lanlee

Reputation: 43

pass value to next page

I have a php page (search.php) which has a link to another php page. (reserve.php). I want to

  1. pass the link text to the next page
  2. display that link text in a input box

Please tell me how should I write the proper coding for the above tasks.

search.php

<a href="Reserve.php"><?php echo $row['AccNo'];?></a>

Upvotes: 3

Views: 305

Answers (3)

abhiburk
abhiburk

Reputation: 2310

Your Search.php have

<a href="Reserve.php?AccNo=<?php echo $row['AccNo']; ?>">Go to Reserve Page</a>

Now On Reserve.php Get that AccNo using GET

$AccNo=$_GET['AccNo'];

and then just echo the $AccNo Variable in your Input Text field

<input type="text" value="<?php echo $AccNo; ?>" >

Hope this helps

Upvotes: 1

Nicolas
Nicolas

Reputation: 8670

You could use the $_SESSION to pass value through pages.

$_SESSION['AccNo'] = $row['AccNo']

You can then access it via $_SESSION['AccNo'] in your other page. Be careful, make sure you started a session using session_start() before use session.

If you prefer using something else, @Max answer was also a pretty way to get data from one page to another, but I would not recommend it for sensitive information.

Upvotes: 0

Max
Max

Reputation: 887

You can use _GET to accomplish that:

<a href="Reserve.php?accno=<?php echo $row['AccNo']?>"><?php echo $row['AccNo'];?></a>

In the new page, the variable value is in the variable $_GET['accno']. To display that text in an input box, simply use echo $_GET['accno'].

Note though that the text will appear in the URL and hence can be altered easily. Depending on the purpose you're using this for, you might want to introduce additional checks, etc. in the new page.

Upvotes: 2

Related Questions