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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.