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 639713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:52:23+00:00 2026-05-13T20:52:23+00:00

Here is the code I dont know whats wrong with it. <?php //Logout code

  • 0

Here is the code

I dont know whats wrong with it.

<?php
       //Logout code
       //Starting Session
       session_start();
       //Include
       include ("includes/mass.php");
       //Check if the user is logged in
       $username = $_SESSION['username'];
       $logged_in_query = "SELECT * FROM    user WHERE loggedin='1' AND    username='$username'";
       $check_if_logged_in =    mysql_query($logged_in_query);
       if (isset($username))

    {       while ($row =    mysql_fetch_array($check_if_logged_in))

            {
                $logged_in = $row['loggedin'];

                if ($logged_in == 1)

                    {
                    //User becomes logged out on database records

                    $sql_logout = "UPDATE user SET loggedin='0' WHERE loggedin='1' AND    username='$username'";

                    $logout_query = mysql_query($logout_query);

                    //Logout page

                    session_destroy();

                    echo "You have been logged out.","<br>"."<a    href='index.php'>Click Here To Go    Back</a>";
                    }
                            }
                }                else

    {
                                echo"You are not logged in"."<br><a href='register.php'>Click    To Sign Up</a>";
                            }           
         ?>
  • 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-05-13T20:52:24+00:00Added an answer on May 13, 2026 at 8:52 pm

    Do you have a mysql link object (from mysql_connect() / mysql_select_db() ?) From your comments below, it doesn’t sound that way.

    This SQL is wrong:

    $sql_logout = "UPDATE user WHERE loggedin='1' AND username='$username'";
    

    Should be:

    $sql_logout = "UPDATE user SET loggedin=0 WHERE loggedin='1' AND username='$username'";
    

    ?

    You probably also mean to be using mysql_fetch_assoc() instead of mysql_fetch_array().

    This line:

    $logout_query = mysql_query($logout_query);
    

    Should be

    $logout_query = mysql_query($sql_logout);
    

    Put in your correct mysql connection and db information and try to run this. Please post the output.

    <?php
    //Logout code
    //Starting Session
    session_start();
    
    echo "hello<br />";
    
    //Include
    include ("includes/mass.php");
    
    echo "no problem in mass.php!<br />";
    
    // FILL ME IN
    $my_link = mysql_connect($server, $username, $password, TRUE);
    mysql_select_db('your_db', $link);
    
    //Check if the user is logged in
    $username = $_SESSION['username'];
    $logged_in_query = "SELECT loggedin FROM user WHERE loggedin='1' AND username='$username'";
    echo $logged_in_query . "<br />";
    
    $check_if_logged_in = mysql_query($logged_in_query, $my_link);
    var_dump(mysql_num_rows($check_if_logged_in));
    
    if (isset($username))
    {
        while ($row = mysql_fetch_assoc($check_if_logged_in))
        {
            var_dump($row);
    
            $logged_in = $row['loggedin'];
    
            if ($logged_in == 1)
            {
                //User become logged out on database records
                $sql_logout = "UPDATE user SET loggedin=0 WHERE loggedin='1' AND username='$username'";
                $logout_query = mysql_query($sql_logout, $my_link);
    
                //Logout page
                session_destroy();
                echo "You have been logged out.","<br>"."<a href='index.php'>Click Here To Go Back</a>";
            }
            else
            {
                echo"You are not logged in"."<br><a href='register.php'>Click To Sign Up</a>";
            }
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dont know what's wrong with this PHP code: $sql = CREATE TABLE test
I don't know what is wrong with this code <?php $items = array('00', '01',
Hi i almost got everything ,but i dont know whats wrong. i have two
I don't know why I'm facing that error ! Here is my code snippet
I'm trying to solve the problem here but I don't know why my code
Im using Doctrine and i dont quite understand this code here: $this->hasColumn('id', 'integer', 8,
All my code is here,quite simple,and I don't konw where it goes wrong. Person
Here is the code I have, and I'm wondering what I'm doing wrong that
Here's my code, I don't know why the checkbox isnt updated when I try
I don't know what I'm doing wrong, but my little update code is giving

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.