Ryan Alcorn
Ryan Alcorn

Reputation: 39

I can't call variables from my other page PHP

<!-- LOGIN -->
        <div id="loginContainer">
            <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='POST'>
            <div id="emailPasswordContainer">
                <input type="text" id="loginInputEmail" placeholder="Email" name="emailA" maxlength="35" required></input>
                <input type="password" id="loginInputPassword" placeholder="Password" name="passwordA" maxlength="35" required></input>
            </div>

                <button type="submit" name="submitLogin" value="submit" id="buttonLogin">
                    <span id="loginText">
                        Login
                    </span>
                </button>
            </form>

            <?php
                $loginErrorMessage = "";
                // start the session and register the session variables
                session_start("ProtectVariables");

                if(isset($_POST['submitLogin'])) {
                    $emailLogin = $_POST['emailA'];
                    $passwordLogin = md5($_POST['passwordA']);

                    $loginQuery = "SELECT email,password FROM account WHERE email='" . $emailLogin . "' AND password='" . $passwordLogin . "'";
                    $loginResult = mysql_query($loginQuery,$db);

                    if(mysql_num_rows($loginResult)==1){
                        if ($_POST['submitLogin']) {
                            header("Location: page2.php?page=1");
                        }
                    }
                    else {
                        $loginErrorMessage = "";
                    }
                }
            ?>

        </div>

This is the code I'm using to login to my website with! But when I get to page2.php?page=1, it won't let me call any of the variables such as $emailLogin or $passwordLogin. The reason I want to use the $emailLogin on page2.php is so I can have it the users first name. I'm not sure if it's a problem with this code or the way I'm calling it on the other page which is just this: echo $emailLogin;

Thank you for your help in advanced! :D

Upvotes: 1

Views: 64

Answers (1)

Udhayakumar
Udhayakumar

Reputation: 271

 $loginQuery = "SELECT email,password FROM account WHERE email='" . $emailLogin . "' AND password='" . $passwordLogin . "'";    
$loginResult = mysql_query($loginQuery);
$admin_row=mysql_fetch_array($loginResult );      
     if (mysql_num_rows($loginResult ) == 1)
         { 

          session_start();
           $getemail=$admin_row['email'];
         //session_register("uname");
         $_SESSION['logged_user']=$getemail;

       header("Location: page2.php?page=1");
            }

in page2.php you can print logged user email using below code

<?php
session_start();
echo $_SESSION['logged_user'];
?>

Upvotes: 1

Related Questions