Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8427071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:41:55+00:00 2026-06-10T04:41:55+00:00

if(isset($_SESSION[‘admin’])) { echo <li><b>Admin</b></li>; } <?php session_name(‘MYSESSION’); session_set_cookie_params(0, ‘/~cgreenheld/’); session_start(); $conn = blah blah

  • 0
if(isset($_SESSION['admin'])) {
echo "<li><b>Admin</b></li>";
}

<?php
session_name('MYSESSION');
session_set_cookie_params(0, '/~cgreenheld/');
session_start();

$conn = blah blah
$query2 = 'Select Type from User WHERE Username = "'.$_SESSION['user'].'" AND Type =\'Admin\'';
$result2 = $conn->query($query2);
if($result2->num_rows==1) {
$_SESSION['admin'] = $result2;
}
?>

Hi, I’m trying to set this session variable but it doesn’t seem to be setting, and i’m wondering if anyone can help. If session[‘admin’] isset it should echo the admin button.
But i’m not quite sure why? (I do have session start and everything on everypage, it’s not a problem with that or any of the “You don’t have php tags” I have checked the mysql query, and it does return something from my table. Any ideas please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:41:56+00:00Added an answer on June 10, 2026 at 4:41 am

    Your session_start(); should be at the top of the page before anything to do with the session variables.

    From the docs:

    When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.

    Edit from comments:

    <?php
        session_name('MYSESSION');
        session_set_cookie_params(0, '/~cgreenheld/');
        session_start();
        // Moved to start after answer was accepted for better readability
        // You had the <?php after this if statement? Was that by mistake?
        if(isset($_SESSION['admin'])) 
        {
            echo "<li><b>Admin</b></li>";
        }
    
        // If you have already started the session in a file above, why do it again here?
    
        $conn = blah blah;
        $query2 = 'Select Type from User WHERE Username = "'.$_SESSION['user'].'" AND Type =\'Admin\'';
        // Could you echo out the above statement for me, just to 
        // make sure there aren't any problems with your sessions at this point?
        $result2 = $conn->query($query2);
        if($result2->num_rows==1) 
        {
            $_SESSION['admin'] = $result2;
            // It seems you are trying to assign the database connection object to it here.
            // perhaps try simply doing this:
            $_SESSION['admin'] = true;
        }
    ?>
    

    Edit 2 from further comments:

    You have to actually fetch the fetch the data like this – snipped from this tutorial which might help you out some more:

    $query  = "SELECT name, subject, message FROM contact";
    $result = mysql_query($query);
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        echo "Name :{$row['name']} <br>" .
         "Subject : {$row['subject']} <br>" .
         "Message : {$row['message']} <br><br>";
    } 
    

    But having said that, while we are talking about it, you would be better off moving away from the old mysql_* functions and move to PDO which is much better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the code <?php session_start(); if(!isset($_SESSION['user_name'])) { header('Location: login.php'); } $conn = mysql_connect(localhost,
<?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo Views=. $_SESSION['views']; echo '<br>'.<a href='destroy.php'>Set Counter1</a>; ?>
<?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views']+ 1; else $_SESSION['views'] = 1; echo views =
So I have the index.php page. <?php session_start(); if (!isset($_SESSION['var1'])) { echo session not
<?php session_start(); if(isset($_POST['sessionNum'])){ //Declare my counter for the first time $_SESSION['initial_count'] = $_POST['sessionNum']; $_SESSION['sessionNum']
I have the following pages: page1.php <?php if (isset($_GET['link'])) { session_start(); $_session['myvariable'] = 'Hello
In my web admin area I have using very simple logic: session_start(); ob_start(); if(!isset($_SESSION['user'])){
my code for the php page displaying the divs <?php session_start(); require_once(classlib/mainspace.php); if (isset($_SESSION['username'])==FALSE)
langauage web. I set 3 links, Français... (href=changeLanguage.php?lang=fr,es,en) changLanguage.php session_start(); if(isset($_SESSION['bckTo']) && isset($_GET['lang'])){ $lang
If (for argument sake) 'admin-access' was granted in php with: if (isset($_SESSION['admin'])) // this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.