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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:03:50+00:00 2026-06-15T15:03:50+00:00

I myself have been trying at this one for about a week. As you

  • 0

I myself have been trying at this one for about a week. As you can clearly see by the haphazard code I have below, I’m trying to create an SQL login system. It uses an SQLite file, and when I run the code to trouble shoot, no PHP errors pop up. I’m assuming this means it’s a problem with the way I check the results, or my SQL. I, for one, am completely lost. Any help is appreciated, thanks.

session_start();

$user = strtolower(sqlite_escape_string($_POST['username']));
$pass = strtolower(sqlite_escape_string($_POST['password']));

$db = sqlite_open('my DB.sqlite', 0666, $sqlerr);

$query = sqlite_query($db, "SELECT COUNT(*) FROM USERS WHERE USER = '$user' AND PASS = '$pass'", $sqlerr);
$result = sqlite_fetch_all($query, SQLITE_ASSOC);

if (count($result) == 1) {
    $_SESSION['loggedin'] = true;
    $_SESSION['loginFail'] = false;
    $_SESSION['user'] = $_POST['username'];
}

if ($sqlerr != null) {
    $_SESSION['sqlerr'] = $sqlerr;
}

if (!$_SESSION['loggedin']) {
    $_SESSION['loginFail'] = true;
}

sqlite_close($db);
header("Location: index.php");
exit();

(Also, sorry if I forgot any information. I’ve not posted a StackOverflow question in a while.)

  • 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-15T15:03:51+00:00Added an answer on June 15, 2026 at 3:03 pm

    Here is your problem:

    $query = sqlite_query($db, "SELECT COUNT(*) FROM USERS WHERE USER = '$user' AND PASS = '$pass'", $sqlerr);
    $result = sqlite_fetch_all($query, SQLITE_ASSOC);
    
    if (count($result) == 1) {
    

    You are asking for a count of rows from the database, which will be something like 1, then you retrieve this result and put it into an array ($result), then count the number of entries in $result. The result of count($result) will always be exactly 1.

    You need to either compare the value that is returned from the database or use SELECT * instead of SELECT COUNT(*)

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

Sidebar

Related Questions

I have been trying to teach myself MEF, starting with this tutorial: http://blogs.msdn.com/b/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx There
I have been spending about 7 hours today, trying to: a) Create my own
so i have been trying to debug this issue myself for a few days
I've been trying to self-teach myself how to code but this practice problem is
I have been trying to teach myself Regexes in python and I decided to
I've recently been trying to teach myself Perl and have been doing some basic
I've been trying to figure this one out for a bit... I even downloaded
Coming from Java Land I have been trying to teach myself Scala. Recently I
I've been driving myself mad over this one. It might be one of those
Iv been trying to figure this one out forever, and its starting to annoy

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.