Jump to content

[HELP] Login panel mysql


iwalidza

Recommended Posts

Dear iwalidza,

do you have a MySQL server set-up already? It can be placed either locally (recommended) or remotely, on another computer. You need to register a user with a secure password as well as a database for use with your resource. And how much experience do you have with MySQL databases in general?

You should use the official MTA database functions to connect to your configured MySQL server, in particular...

  • dbConnect - call it once at start of resource to initialize a database connection handle (you need a host, username and password, etc)
  • dbExec - creating new accounts into the MySQL database
  • dbQuery with dbPoll and dbFree - taking account information out of your database

In order to implement "This name already exists" you need to query the accounts SQL table on the "username" column and see if any row with that username already exists, for example...

SELECT * FROM accounts WHERE username="iwalidza"

If you were to use dbQuery on this statement in combination with dbPoll/dbFree you could check the existance of accounts prior to creating a double account. :) 

I found an accounts system that claims to use MySQL under-the-hood in the MTA resources community: https://community.multitheftauto.com/index.php?p=resources&s=details&id=7263
Please take a look at it and compare it with what you want to implement.

Edited by The_GTA
  • Like 2
Link to comment
8 minutes ago, iwalidza said:

@The_GTA thank you so much for that and yup i have a local database server and i know somthing for that
but with error i dont know anythink

Do you have a database layout and a script with a login panel? We could work it out.

Link to comment

I recommend to check for an existing account like...

-- I assume that there is a variable called "db_conn" with the MySQL connection.

local function does_account_exist(username)
  local query = dbQuery(db_conn, "SELECT username FROM accounts WHERE username='?'", username);
  
  if not (query) then
    return false;
  end
  
  local results = dbPoll(query, -1);
  
  if not (results) then
    return false;
  end
  
  return ( #results >= 1 );
end

Then you can use the "does_account_exist' function as part of if-condition to check for the existance. Like...

local function create_error_message_dialog(msg)
  -- TODO: write the GUI logic in here.
end

local function create_account(username, password)
  if (does_account_exist(username)) then
    create_error_message_dialog("This name already exists");
    return;
  end
  
  -- TODO: use dbExec to register a new account.
end

 

  • Like 1
Link to comment
  • 10 months later...

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...