Sign in to follow this  
echoHU

Cannot read property 'query' of null

Recommended Posts

Hello! I made this resource, and when i enter any information in game the console says this:

C:\Users\varad\Desktop\PleasantRoleplay\packages\PleasantRoleplay\user-system\Login.js:11: TypeError: Cannot read property 'query' of null
        db.Handle.query("SELECT * FROM accounts WHERE username = ?", username, function(e, result) {

Login.js:

var db = require('../mysql/Connection');

mp.events.add('playerJoin', player => {
	player.call('loginShowPanel');
	
	let alpha = player.alpha;
	player.alpha = 0;
});

mp.events.add('loginSendInformation', (player, username, password) => {
	db.Handle.query("SELECT * FROM accounts WHERE username = ?", username, function(e, result) {
		if ( result.length ) {
			player.call('loginClosePanel');
          
            let alpha = player.alpha;
			player.alpha = 255;
		} else player.outputChatBox("<b style='color: red'>This Username doesn't exist!</b>");        
	});
});

Connection.js:

var mysql = require('mysql');

module.exports = {
	Handle: null,
    Connect: function(callback) {
        this.Handle = mysql.createConnection({
            host     : 'localhost',
            user     : 'root',
            password : '',
            database : 'pleasantroleplay'
        });
        this.Handle.connect(function(e) {
            if ( !e ) { callback(); }
            else console.log ("DATABASE ERROR" + e);
         });        
    }
};

Index.js:

require('./mysql/Connection');

require('./user-system/Login.js');

I have added Mysql module through npm.

 

Edited by echoHU

Share this post


Link to post
Share on other sites
On 11/24/2018 at 11:26 PM, MrPancakers said:

Ignore this I read your file structure wrong.

I am here to learn and get some help..🙄

Share this post


Link to post
Share on other sites
14 hours ago, echoHU said:

I am here to learn and get some help..🙄

I wasn't talking to you, I was saying to ignore my message, I had edited it because I read your question wrong. I can't delete replies.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.