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

  • Home
  • SEARCH
  • 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 6221331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:06:51+00:00 2026-05-24T08:06:51+00:00

Would someone be able to give me a MySQL relation query for looking up

  • 0

Would someone be able to give me a MySQL relation query for looking up a column value of a table based off of another value of the same table?

For instance, I have a table with 4 columns (id, name, email, password). How could I look up the the value of the “id” column of a certain user based off of their email in the “email” column and store the result (id) in a variable?

Here’s the session() controller function

function userIsLoggedIn()
{
    if (isset($_POST['action']) and $_POST['action'] == 'login')
    {
        if (!isset($_POST['email']) or $_POST['email'] == '' or
            !isset($_POST['password']) or $_POST['password'] == '')
        {
            $GLOBALS['loginError'] = 'Please fill in both fields';
            return FALSE;
        }

        $password = md5($_POST['password'] . 'chainfire db');

        if (databaseContainsAuthor($_POST['email'], $password))
        {
            session_start();
            $_SESSION['loggedIn'] = TRUE;
            $_SESSION['email'] = $_POST['email'];
            $_SESSION['password'] = $password;
            $_SESSION['authorid'] = $author;
            return TRUE;
        }
        else
        {
            session_start();
            unset($_SESSION['loggedIn']);
            unset($_SESSION['email']);
            unset($_SESSION['password']);
            unset($_SESSION['authorid']);
            $GLOBALS['loginError'] =
                    'The specified email address or password was incorrect.';
            return FALSE;
        }
    }

I’ve tried

SELECT id FROM article WHERE email='$email' 

Is there a more efficient way to do it? I’m also not totally sure how to store the result of the query in the $author session variable.

Thanks in advance.

  • 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-24T08:06:51+00:00Added an answer on May 24, 2026 at 8:06 am

    Your query is perfect (with the proviso that you are sanitising the $email variable – see the tale of Little Bobby Tables).

    SELECT id FROM article WHERE email='$email'
    

    And to perform that query and set the variable $author to the returned value is simply:

    $author = 0;
    if( ( $idFromEmail = @mysql_query( "SELECT id FROM article WHERE email='".mysql_real_escape_string( $email )."'" ) )
        && mysql_num_rows( $idFromEmail )==1
        && ( $r = mysql_fetch_assoc( $idFromEmail ) ) ){
        $author = $r['id'];
    }
    

    Rewritten in long form, if the above is too complex to follow:

    $author = 0;
    if( !( $idFromEmail = @mysql_query( "SELECT id FROM article WHERE email='".mysql_real_escape_string( $email )."'" ) ){
      // SQL Query Failed
    }elseif( mysql_num_rows( $idFromEmail )!=1 ){
      // More than, or less than, one row returned
    }else{
      $r = mysql_fetch_assoc( $idFromEmail );
      $author = $r['id'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably an simple problem but would someone nice be able to give
Would someone be able to break down the Ruby specifics of what each of
I was wondering if someone would be able to help me write a CQL
Why would someone use numeric(12, 0) datatype for a simple integer ID column? If
I was tasked with developing an application that would be able to tell someone
Is someone able to give me a quick tutorial how to install cvBlob on
I need to be able to give users the ability to call someone or
would someone please write this code: this.Loaded += (s, e) => this.loaded = true;
Why would someone want to use a linked-list over an array? Coding a linked-list
Why would someone use WHERE 1=1 AND <conditions> in a SQL clause (Either SQL

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.