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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:15:23+00:00 2026-06-17T14:15:23+00:00

what is wrong with this logic? var selectString = ‘SELECT EXISTS(SELECT 1 FROM users

  • 0

what is wrong with this logic?

var selectString = 'SELECT EXISTS(SELECT 1 FROM users WHERE user="'+username+'")';

var queryUserExists = connection.query(selectString);
var resultsLength = queryUserExists._results.length;

console.log(queryUserExists);

if(resultsLength > 0){
   socket.write("fail user already exists"+"\r\n");

} else {
    console.log('insert=');
    var query = connection.query (
        'INSERT INTO users '+
        'SET user = ?, password = ?, token = ?',
        [username, password, token]
    );

    socket.write("success"+"\r\n");
}

resultsLength is always returned zero.
What is the proper way to use this query?

returned object:

sql: 'SELECT 1 FROM users WHERE user = \'a new user is my name\' ORDER BY user LIMIT 1',
typeCast: true,
nestTables: false,
_resultSet: null,
_results: [],
_fields: [],
_index: 0,
_loadError: null }
  • 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-17T14:15:25+00:00Added an answer on June 17, 2026 at 2:15 pm

    The proper code: thanks to https://stackoverflow.com/users/722783/mahmoud-gamal for the database query that is optimized!

    connection.query("SELECT 1 FROM users WHERE user = '"+username+"' ORDER BY user LIMIT 1", function (error, results, fields) {
    if (error) {
        console.log(error);
        socket.write("fail internal error"+"\r\n");
    }
    if (results.length  > 0) {
        console.log('fail');
        socket.write("fail user already exists"+"\r\n");
    
    } else {
    
    
            console.log('insert');
            var query = connection.query (
                'INSERT INTO users '+
                'SET user = ?, password = ?, token = ?',
                [username, password, token]
            );
    
            socket.write("success"+"\r\n");
    
    
    }
    
    console.log(results);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me what's wrong with this sp. The logic seems to
Can anyone see anything wrong with this login script: public function login($username, $pass, $remember)
What wrong with this validation: Jquery: $(document).ready(function(){ $(#addcmd).attr(disabled,disabled); $(#cmdstxt).keypress( function(event){ var txt=$(#cmdstxt); if( txt.val().length
what wrong with this Query ??? i need this Query. UPDATE user_preferences SET user_preferences_value
What is wrong with this login script? I have a modal-style iframe login box
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
Why is this wrong? <table> <form> <tr><td>something something</td/> </form> </table> I'm talking about position
Whats wrong with this code? -(void) drawRect:(CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); if
Whats wrong with this picture? Model: validates_acceptance_of :terms_of_service, :on => :create, :accept => true,
whats wrong with this? anybody help me please.. if(stripos($nerde, $hf) !== false) && (stripos($nerde,

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.