0

I have a Login Page with the following Code;

                <p> Login  Name</p>
                <p>
           <input type="text" 
                  name="username" id="username">


    <input type="submit" name="submit" value="submit">


        </p>
            <p>
              <label for="password">Password<br />
                <br />
              </label>
              <input name="password" 
              type="password" id="password"></input>

            </p>

        <p>

          <input type="submit" value="Login"/>
          <input type="reset" value="Reset"/>
          </p>
        <p><br />

and after capturing

i have also this code using the inputs

   require('config\db.php');
  session_start();
  // If form submitted, insert values into the database.
  if (isset($_POST['username'])){
  //$username1 = $_POST['username1'];;
    $username = $_POST['username'];
    $password = $_POST['password'];
    $username = stripslashes($username);
    $username = mysql_real_escape_string($username);
    $password = stripslashes($password);
    $password = mysql_real_escape_string($password);

I open a Page which has some options on logging in . I select one option on that page using radio buttons. It opens a third page.

I want to display the User Name captured on the first page.

How can i do this? Any help will be highly appreciated.

  • 2
    **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Oct 28 '15 at 15:16
  • Since you'll probably want the username again sometime try http://php.net/manual/en/book.session.php – AbraCadaver Oct 28 '15 at 15:18
  • don't blindly strip slashes from text. You're simply ASSUMING that magic_quotes is enabled, and you risk mangling a user's password if they really do have a backslash in it. – Marc B Oct 28 '15 at 15:18
  • Thanks , i will latter upgrade to isql – Azhar Bhatti Oct 30 '15 at 12:23

2 Answers2

0

You have to store it somewhere.

A hidden input in the form in the second page is pretty reliable.

A session is a common choice, although subject to race conditions.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Store that user name in session
Then you can use it anywhere

To use session to should write session_start(); which you have done.

Now just store your username in session.

$_SESSION['username']=$username;

echo you can print it by just

echo $_SESSION['username'];

for more information go here

Swap
  • 165
  • 3
  • 12
  • Thanks a lot , i have tried and get the error ;Notice: Undefined variable: _SESSION in C:\xampp\htdocs\sh\server\SymptomorDisease.php on line 62. I have even tried to add the . Still same error. Please assist. – Azhar Bhatti Oct 30 '15 at 12:20
  • You need to start the session using session_start(); [check this](http://stackoverflow.com/questions/9650090/undefined-variable-session) – Swap Oct 30 '15 at 13:42
  • Another related question . If instead of echoing i need to input it into a input box or label . How do i do it ? I tried but it didnt work? This is on the third page – Azhar Bhatti Oct 30 '15 at 13:58
  • try this – Swap Oct 31 '15 at 06:07