Jump to content

Cannot read property 'query' of null


echoHU

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
Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...