0

I have my code set up to display the username in the nav bar however its displaying their password?

nav.php

<li>
   <a href class="userName"><?php echo $_SESSION['userName'];?></a>
</li> 

connectivity.php

function SignIn() 
{ 
    session_start(); //starting the session for user profile page 
    if(!empty($_POST['user'])) //checking the 'user' name which is from Sign-In.html, is it empty or have some text 
    { 
        $user = $_POST[user];
        $pass = $_POST[pass];

            $query = "SELECT * FROM UserName where userName = '$user' AND pass = '$pass'";
            $query = mysql_query($query) or die(mysql_error()); 
        $row = mysql_fetch_array($query) or die(mysql_error());
        if(!empty($row['userName']) AND !empty($row['pass'])) 
        { 
            $_SESSION['userName'] = $row['pass']; 
            header("location: ../PHP/Cart.php");

        } else { 
            echo "SORRY... YOU ENTERD WRONG ID AND PASSWORD... PLEASE RETRY..."; 
            } 
        } 
    } 
    if(isset($_POST['submit'])) 
    { 
        SignIn(); 
    } 

in the nav.php you can see its echoing the $_SESSION['userName'] however its displaying their password?

1

This must be a clue:

$_SESSION['userName'] = $row['pass'];

You should also enable full error_reporting whilst developing. (It will throw up some other warnings.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.