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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:40:48+00:00 2026-06-12T17:40:48+00:00

Well, something going wrong here. I type username and password which are exist in

  • 0

Well, something going wrong here. I type username and password which are exist in my DB. It should echo this string in such situations

need to activate

but it echo this

You need to reg

init.php

<?php
    //error_reporting(0);
    session_start();

    require 'dbconnect.php';//this works okay so i wouldn't post this file code
    require 'users.php';

    $errors = array();
?>

users.php

        <?php

        function user_exists($username){
            $username = mysql_real_escape_string($username);

            $query = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE 'username' = '$username'");

            if (!$query) {
                die('Could not query:' . mysql_error());
            }

            return (mysql_result($query, 0) == 1) ? true : false;

        }

        function user_active($username){

            $username = mysql_real_escape_string($username);

            $querytoo = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE 'username' = '$username' AND 'active' = 1");

            if (!$querytoo) {
                die('Could not query:' . mysql_error());
            }

            return (mysql_result($querytoo , 0) == 1) ? true : false;

        }
    ?>

login.php

<?php
include 'init.php';


if(empty($_POST) === false){
    $username = $_POST['username'];
    $password = $_POST['password'];

    if(empty($username) === true || empty($password) === true){
        $errors[]='You need to enter a username and password';
    } 
    elseif(user_exists($username) === false){
        $errors[]='You need to reg';
    } 
    elseif(user_active($username) === false){
        $errors[]='need to activate';
    } 
    else {
    //
    }

    print_r($errors);
}



?>

part of html

<form action="login.php" method = "post">
                    <ul id="login">
                        <li>
                            username:<br>
                            <input type="text" name="username" size="30" value=""/></li>
                        <li>password:<br>
                            <input type="password" name="password" size="30" value=""/></li>
                        <li><input type = "submit" value ="Log in"></li>
                        <li>
                            <a href="register.php"> Register</a>
                        </li>
                    </ul>

P.S.
text of querys is works fine, i checked it in mysql. in php code when I type “ instead of ” here

SELECT COUNT(‘user_id’) FROM users WHERE ‘username’ = ‘$username’
AND ‘active’ = 1

appears

‘Could not query:’

thing

and i tried elseif and else if things so i don’t think that problems is there

  • 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-12T17:40:49+00:00Added an answer on June 12, 2026 at 5:40 pm

    Your SQL is wrong. You are comparing a static strings to your value, not a column name:

        SELECT COUNT('user_id') FROM users WHERE 'username' = '$username' AND 'active' = 1
    

    should be

    SELECT COUNT(user_id) FROM users WHERE username = '$username' AND active = 1
    

    Note that I removed the ‘ from the column names. It is also valid to use backticks:

    SELECT COUNT(`user_id`) FROM users WHERE `username` = '$username' AND `active` = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know SQL well but I must be missing something really dumb here. This
It may well be that I have to write something overly complex for this
I don't know if this is a well known 'thing' or something new in
I am following this tutorial . All is going well until I try create
Well, I am new to CakePHP. So a painful day to debug this. Here
I have a fairly simple script but something is going wrong and I can't
Well,I am trying to do something similar what I did in Adobe Flex.Consuming a
I know C# well, but it is something strange for me. In some old
I think I know C++ reasonably well and I am thinking about implementing something
I thought I was pretty well acquainted with Subversion, but now something I thought

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.