简体   繁体   中英

passing variable to the next page in php

i have this code below and i cannot seem to understand why the i cannot see $pId in the next page. i seem that he doesnt send the variable in $pId in profile.php please help

  <?php
        include 'config.php';
        include 'dbconnection.php';
session_start();

        if(isset($_REQUEST["pwd"]) && isset($_REQUEST["name"]))
        {
            $password = $_REQUEST['pwd'];
            $name = $_REQUEST['name'];

                    $checkUserPass = mysql_query("SELECT * FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'", $conn);
                    if(mysql_num_rows($checkUserPass) == 1)
                    {   


                        $sql="SELECT PersonnelID FROM validPersonnel WHERE Passkey = :password and Name = :name";
                        $query=$db->prepare($sql);
                        $query->execute(array('name' => $name, 'password' => $password));
                        $row = $query->fetch();
                        $_SESSION['personnelId'] = $row['PersonnelID'];

                        header("Refresh: 1; url=profile/profile.php?p_id={$pId}");
                        echo "<br/><br/>";
                        echo "<script>alert('Logged In.')</script>";


                    }
                    else
                    {
                        //  print_r($query);
                        echo "<br/><br/>";
                        echo "<script>alert('Wrong Password.')</script>";
                        header('Refresh: 1; url=personnelselect.php');
                    }
        }

        mysql_close($conn);
    ?>

the code below is the link where i pass the $pId

            if(isset($_SESSION['personnelId']))
            {
            $id = $_SESSION['personnelId'];
            $sqlLoader="Select Name from validpersonnel where PersonnelID = :id";
            $resLoader=$db->prepare($sqlLoader);
            $resLoader->execute(array('id' => $id));
            $row = $resLoader->fetch();
            echo $row['Name'];
            }
        ?>

Almost all variables are destroyed when a script ends. I would recommend using a $_SESSION variable or passing the variables via $_GET.

For example to store the variable:

$_SESSION['pid'] = $pId;

To retrieve the variable:

if (isset($_SESSION['pid'])) $pId = $_SESSION['pid'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM