Trying to call session variables to display

Discussion in 'PHP' started by deadkirakamikazi, Apr 24, 2013.

  1. #1
    Hi there,
    To put it simple, im trying to use this
    <?php
    //We check if the users ID is defined
    if(isset($_GET['id']))
    {
        $id = intval($_GET['id']);
        //We check if the user exists
       
        $dn = mysql_query('SELECT * FROM members username, email_address, signup_date WHERE id="'.$id.'"');
       
        if(mysql_num_rows($dn)>0)
        {
            $dnn = mysql_fetch_array($dn);
            //We display the user datas
    ?>
    Your Details: "<?php echo htmlentities($dnn['username']); ?>" :
    </td>
            <td class="left"><h1><?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?></h1>
            Email: <?php echo htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); ?><br />
            This user joined the website on <?php echo date('Y/m/d',$dnn['signup_date']); ?></td>
        </tr>
    </table>
    <?php
        }
        else
        {
            echo 'This user dont exists.';
        }
    }
    else
    {
        echo 'The user ID is not defined.';
    }
    ?>
    PHP:
    To display certain info pulled from the database to display using echo. However the code keeps getting re-directed to echo 'The user ID is not defined.'; im not sure where the code has gone wrong.


            <?php
                session_start();
                include('db.php');
                print_r($_SESSION);
            ?>
    PHP:
    is running from the top of the html page.

    if anyone can spare some time to help me out i would greatly appreciate it.

    Thanks
     
    deadkirakamikazi, Apr 24, 2013 IP
  2. deadkirakamikazi

    deadkirakamikazi Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    Not to worry fixed :),

    Registered Session Variables

            session_register('id');
            $_SESSION['id'] = $id;
            session_register('first_name');
            $_SESSION['first_name'] = $first_name;
            session_register('last_name');
            $_SESSION['last_name'] = $last_name;
            session_register('email_address');
            $_SESSION['email_address'] = $email_address;
            session_register('special_user');
            $_SESSION['user_level'] = $user_level;
    PHP:
    Then:

                    <?php
                          echo  'Username ', $_SESSION['username'];
                          echo  "<br>";
                          echo  'email ', $_SESSION['email_address'];
                          echo  "<br>";
                          echo    'Joined on ', $S_SESSION['signup_date'];
                    ?>
    PHP:
    This worked much easier and efficently! when your not loged in you wont see the page so no reason for else or die script/logic.

    (posted fix for those if they need help fixing this problem one day)
     
    deadkirakamikazi, Apr 24, 2013 IP