OK. I did lots of searching, but can't find anything helpful about MY issue. OK, problem...

Anyway, what I want to do is take the value of the result set field "Key" and place it into a session variable for use elsewhere in the app. In "login.php" a successful login fires the line "$SESSION["key"] = $row['Key'];", then goes to another page. On that second page, "test.php," I want to display the value to make sure I captured it accurately. Right now it ("$SESSION["key"]") is blank, and I don't know why. Everything I've read so far tells me I'm doing this right, but it still doesn't work. Here's what I hope is enough "snippetting" to outline what I'm doing:

login.php:
<?php
session_start();
$sql="SELECT * FROM $table WHERE $UserFieldName='$username' AND $PasswordFieldName='$password'";
$result=mysql_query($sql);
$result = mysql_num_rows($result);
if($result!="0")
{ // If it does exsist
$SESSION["password"] = $password;
$
SESSION["username"] = $username;
$SESSION["loggedin"] = true;
$
SESSION["key"] = $row['Key'];
?>
<script type="text/javascript">
window.location = "test.php"
</script>
<?php
}
?>

test.php:
<?php
session_start();
if ($SESSION["loggedin"] != true)
{
?>
<script type="text/javascript">
window.location = "login.php"
</script>
<?php
}
else
{
echo "key = " . $
SESSION["key"];
}
?>

Everything works fine, except the line "echo "key = " . $_SESSION["key"];." It shows "key ="

What am I overlooking? 😕

    Oh, I forgot to mention... "Key" is a valid field name in the query.

      StateGuy wrote:

      login.php:
      <?php
      session_start();
      $sql="SELECT FROM $table WHERE $UserFieldName='$username' AND $PasswordFieldName='$password'";
      $result=mysql_query($sql);
      $result = mysql_num_rows($result); /
      personally, i'd start here. i'd put something like $result_count = mysql_num_rows ($result); */
      if($result!="0") // if ($result_count =1)

      { // If it does exsist
      $SESSION["password"] = $password;
      $
      SESSION["username"] = $username;
      $SESSION["loggedin"] = true;
      $
      SESSION["key"] = $row['Key'];
      ?>

      your if statment looks funky to me... you're setting $SESSION['password'] equal to some undefined array called $password.(?) should be the other way around. $password is equal to whatever value $SESSION['password'] is. $password=$_SESSION['password']; right??

      StateGuy wrote:

      test.php:
      <?php
      session_start();
      if ($SESSION["loggedin"] != true)
      {
      ?>
      <script type="text/javascript">
      window.location = "login.php"
      </script>
      <?php
      }
      else
      {
      echo "key = " . $
      SESSION["key"];
      }
      ?>

      Everything works fine, except the line "echo "key = " . $_SESSION["key"];." It shows "key ="

      What am I overlooking? 😕

      well, if what you're saying is the case, then i'd use single quotes for the echo and try that first. i'm still learning php but i've noticed sometimes switching a double quote to a single on a print or echo makes a difference..

        Write a Reply...