By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

how to print a username in 2nd page using php

P: 18
i input a username in a textfield this is in 1st page
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?php
  4.           if(isset($_POST['Submit']))
  5.           {
  6.           $username=$_POST['textfield'];
  7.                   }
  8. ?>
  9.  
  10.  
in next page i want to display this username in a form

how to do?
May 7 '10 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
Store the data in the session[1], or use query-string[2] data.

Using the session:
page1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.  
  5. $_SESSION['username'] = "curi444";
  6.  
  7. echo "<a href='page2.php'>Go to page 2</a>";
  8.  
  9. ?>
page2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if (isset($_SESSION['username'])) {
  6.     echo $username;
  7. }
  8. else {
  9.     echo "No username set. <a href='page1.php'>Go tp page 1</a>";
  10. }
  11.  
  12. ?>
Using the query-string:

page1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $username = 'curi444';
  4.  
  5. printf("Go to <a href='page2.php?username=%s'>page 2<a/>.",
  6.        $username
  7. );
  8.  
  9. ?>
page2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if (isset($_GET['username'])) {
  4.     printf("Hello, %s.", $_GET['username']);
  5. }
  6. else {
  7.     echo "No username. Go to <a href='page1.php'>page 1</a>.";
  8. }
  9.  
  10. ?>
[1] http://www.php.net/manual/en/book.session.php
[2] http://www.php.net/manual/en/reserved.variables.get.php
May 7 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.