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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:01:48+00:00 2026-05-24T19:01:48+00:00

please help i have the following php code for my login session but i

  • 0

please help i have the following php code for my login session but i am trying to get the $_session[‘user_id’] instead of the $_session[’email’]. i tried print_f function to see what i can use but user_id array says 0 which cannot be right unless i read it wrong.

session_start();

$email = strip_tags($_POST['login']);
$pass = strip_tags($_POST['password']);

if ($email&&$password) {
    $connect = mysql_connect("xammp","root"," ") or die (" ");
    mysql_select_db("dbrun") or die ("db not found");
    $query = mysql_query("SELECT email,pass FROM members WHERE login='$email'");
    $numrows = mysql_num_rows($query);
    if ($numrows!=0) {
        // login code password check
        while ($row = mysql_fetch_assoc($query)) {
            $dbemail = $row['login'];
            $dbpass = $row['password'];
        }

        // check to see if they match!
        if ($login==$dbemail&&$password==$dbpass) {
            echo "welcome <a href='member.php'>click to enter</a>";
            $_SESSION['login']=$email;
        } else {
            echo (login_fail.php);
        }
    } else {
        die ("user don't exist!");
    }
    //use if needed ==> echo $numrows;
} else {
    die ("Please enter a valid login");
}

i am trying to get the $_session[‘user_id’] instead how can get this to use instead of $_session[’email’]. tried using $_session[‘user_id’] but instead i got undefined error msg.

  • 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-24T19:01:49+00:00Added an answer on May 24, 2026 at 7:01 pm

    Well, you don’t define $_session[‘user_id’] anywhere in this script, so it’s no surprise that it’s not defined. You have to assign it a value before you can refer to it.

    Also, note that there all kinds of security problems with this code.

    You’re running your MySQL connection as the root user. This is NOT a good idea.

    You’re trusting user input, which opens your script up to a SQL injection attack. Stripping HTML tags from the user input does not make it safe. Suppose that I came to your site, and filled in the “email” field with this:

    bob@example.com'; GRANT ALL PRIVILEGES ON *.* TO 'evil_bob' IDENTIFIED BY '0wned_joo';

    As currently written, your script would happily run its query as normal, and also create an account called “evil_bob” with full privileges to all the information in all of the databases on your server.

    To avoid this, NEVER assume that user input is safe. Validate it. And to be extra sure, don’t stick variables straight into SQL you’ve written. Use bound parameters instead. There are a few cases where it’s hard to avoid — for example, if you need to specify the name of a column rather than a piece of data, a bound parameter will not help and you’ll have to do it some other way. However, for any piece of data you’re using as part of a query, bind it.

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

Sidebar

Related Questions

I am using following PHP code for trigger creation but always get error, please
please have a look at the following code. When the value of i ==
i have used following code in my c# application string verification_url = @http://site.com/posttest.php?; string
I have following code which works fine in firefox and ie 8, but in
I have the following php code: <html> <body> <?php $_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML');
I am using wordpress and on the page sidebar.php I have the following code:
I have the following PHP code to display my tag cloud. It seems if
Please help! Background info I have a WPF application which accesses a SQL Server
I might have wandered into wrong direction so please help. I have a page
I cannot understand how this is possible. Please help!! I have an app with

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.