Jump to content

session variables :S


fallenangel1983

Recommended Posts

Having loads of trouble integrating these session variables and have tried the online tutorials but i am having a specific problem. can you help please.

 

I havea basic html form which allows users to enter a username and password. the next page is a php form and i use the following code:

 

session_start();

 

mysql_connect blah blah

mysql_select_db blah blah

 

--now i have the following variables from the previous form:

 

$username = $_POST['username'];

$password = $_POST['password'];

$_SESSION['username'] = $username;

$_SESSION['password'] = $password;

 

and now i start my sql to validate the data (which all works)

it then (if info is correct) sends to a new page (which again all works).

 

my problem is this. on the next page when i try to echo the username and password on the screen using this code:

 

echo "{$_SESSION['username']}  and  {$_SESSION['password']}

 

it returns the following statement:

 

 

and bob (or hatever username i inserted)

 

 

 

it remembers the username but the password. ive checked the code again and again and the username an password code is the same.

 

can anyone help. will post more code if needed. just didnt want to flood the page with code.

Link to comment
Share on other sites

--HTML page

 

<?php #LoginPage : LoginPage.php

session_start();

?>

 

<html>

<head>

  <title>Login Screen</title>

</head>

<body bgcolor="lightyellow">

  <table width="100%" border="0">

    <tr>

      <td><center><img src="img/Logo.jpg"></a></td>

    </tr>

    <tr></tr>

    <tr></tr>

    <tr></tr>

    <tr></tr>

    <tr>

      <td><center>

  <table width="300" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="black">

    <tr>

      <form name="form1" method="post" action="CheckLogin.php">

        <td>

          <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="cyan">

            <tr>

              <td colspan="3"><strong><center> Member Login </strong></center></td>

            </tr>

            <tr>

              <td width="78">Username</td>

              <td width="6">:</td>

              <td width="294"><input name="username" type="username" id="username"></td>

            </tr>

            <tr>

              <td>Password</td>

              <td>:</td>

              <td><input name="password" type="password" id="password"></td>

            </tr>

            <tr>

              <td colspan="3"><center><input type="submit" name="Submit" value="Login"></center></td>

            </tr>

          </table>

        </td>

      </form>

    </tr>

  </table>

      </td>

    </tr>

  </table>

</body>

</html>

 

--PHP page

 

<?php

 

session_start();

 

$db_name="project";

 

mysql_connect("localhost","root","") or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

$username = $_POST['username'];

$password = $_POST['password'];

$_session['username'] = $username;

$_session['password'] = $password;

 

  $sql="SELECT * FROM users WHERE username='$username' and password='$password'";

 

  $result=mysql_query($sql);

  $count=mysql_num_rows($result);

 

  if($count==1)

  {

    while($row=mysql_fetch_row($result))

    {

      $username = $row[0];

      $password = $row[1];

      $idType  = $row[2];

 

      if($idType==1)

      {

        header("location:Users.php");

      }

      elseif($idType==2)

      {

        header("location:Admin.php");

      }

      elseif($idType==3)

      { 

        header("location:Management.php");

      }

    }

  }

  else

  {

    echo "Wrong Username or Password <br><a href='./LoginPage.php'>Go Back</a>";

  }

?>

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.