Jump to content

Weird script problem


 Share

Recommended Posts

Hi,

I'm working on a project last days but I can't seem to figure out why something isn't working.

I'm working with MySQL and im using the UDF cdkid made.

Now, the problem is:

This is working for me:

#include <Array.au3>
#include <MySQL.au3>

$Con = _MySQLConnect("root", "", "realmd", "127.0.0.1")
$Var = _GetColVals($Con, "accounts", "username")
_ArrayDisplay($Var)

Now build into my main script, it won't work:

#include <Array.au3>
#include "MySQL.au3"

Global $Settings_Dir = @TempDir & "\wow_user_manager.ini"
Global $Host_Address, $Username, $Password, $Port, $Con, $Status

If Not FileExists($Settings_Dir) Then
    _AskDbInfo()
Else
    $Host_Address = IniRead($Settings_Dir, "db_info", "host", "N\A")
    $Username = IniRead($Settings_Dir, "db_info", "username", "N\A")
    $Password = IniRead($Settings_Dir, "db_info", "password", "N\A")
    $Port = IniRead($Settings_Dir, "db_info", "port", "N\A")
    _Main()
EndIf

Func _AskDbInfo()
    $GUI = GUICreate("World of Warcraft: User Manager [Database Info]", 210, 160)
    GUICtrlCreateLabel("Host address", 10, 10)
    $Host_Address_Input = GUICtrlCreateInput("127.0.0.1", 100, 7, 100)
    GUICtrlCreateLabel("Username", 10, 40)
    $Username_Input = GUICtrlCreateInput("root", 100, 37, 100)
    GUICtrlCreateLabel("Password", 10, 70)
    $Password_Input = GUICtrlCreateInput("", 100, 67, 100, 20, 0x0020)
    GUICtrlCreateLabel("Port", 10, 100)
    $Port_Input = GUICtrlCreateInput(3306, 100, 97, 100)
    $Save = GUICtrlCreateButton("Save Information", 10, 130, 190)
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
        Case -3
            Exit
        Case $Save
            IniWrite($Settings_Dir, "db_info", "host", GUICtrlRead($Host_Address_Input))
            IniWrite($Settings_Dir, "db_info", "username", GUICtrlRead($Username_Input))
            IniWrite($Settings_Dir, "db_info", "password", GUICtrlRead($Password_Input))
            IniWrite($Settings_Dir, "db_info", "port", GUICtrlRead($Password_Input))
            GUIDelete($GUI)
            _Main()
        EndSwitch
    WEnd
EndFunc

Func _Main()

    $GUI = GUICreate("World of Warcraft: User Manager", 500, 500)
    GUICtrlCreateGroup("Account Creation", 10, 10, 210, 225)
    GUICtrlCreateLabel("Username", 20, 30)
    $Account_Username_Input = GUICtrlCreateInput("", 110, 27, 100)
    GUICtrlCreateLabel("Password", 20, 60)
    $Account_Password_Input = GUICtrlCreateInput("", 110, 57, 100, 20, 0x0020)
    GUICtrlCreateLabel("GM Level", 20, 90)
    $Account_GMLevel_Input = GUICtrlCreateCombo("", 110, 87, 100)
    GUICtrlCreateLabel("Email", 20, 120)
    $Account_Email_Input = GUICtrlCreateInput("", 110, 117, 100)
    GUICtrlCreateLabel("WoW Version", 20, 150)
    $Account_Version = GUICtrlCreateCombo("", 110, 150, 100)
    $CreateAccount = GUICtrlCreateButton("Create Account", 20, 180, 190)
    $Status = GUICtrlCreateLabel("Status:", 20, 210, 190, 15)
    
    GUICtrlCreateGroup("User Management", 230, 10, 500, 500)
    $Username_Search = GUICtrlCreateInput("", 240, 27, 100, 20)
    $Search = GUICtrlCreateButton("Search Username", 350, 24, 100)
    
    GUISetState()
    GUICtrlSetData($Account_Version, "0|1|2")
    GUICtrlSetData($Account_GMLevel_Input, "0|1|2|3|az")
    $Con = _Connect($Host_Address, $Username, $Password, $Port)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
        Case -3
            Exit
        Case $CreateAccount
            $Query = "INSERT INTO accounts (username, sha_pass_hash, gm_level, email, wow_version) VALUES ('" & _
                    GUICtrlRead($Account_Username_Input) & "', '" & GUICtrlRead($Account_Password_Input) & "', '" & _
                    GUICtrlRead($Account_GMLevel_Input) & "', '"  & GUICtrlRead($Account_Email_Input) & "', '" & _
                    GUICtrlRead($Account_Version) & "')"
                    
            _Query($Con, $Query)
            If @error = 1 Then
                MsgBox(16, "ERROR", "Query failed.")
            Else
                MsgBox(64, "SUCCES", "Query succesfull!")
                GUICtrlSetData($Account_Username_Input, "")
                GUICtrlSetData($Account_Password_Input, "")
                GUICtrlSetData($Account_GMLevel_Input, "")
                GUICtrlSetData($Account_Email_Input, "")
                GUICtrlSetData($Account_Version, "")
            EndIf
        Case $Search
            $var = _GetColVals($Con, "accounts", "username")
            _ArrayDisplay($var)
        EndSwitch
    WEnd
EndFunc

Func _Connect($sHost, $sUsername, $sPassword, $sPort)
    $Con = _MySQLConnect($sUsername, $sPassword, "realmd", $sHost, "{MySQL ODBC 3.51 Driver}", $sPort)
    If @error = 1 Then
        GUICtrlSetData($Status, "Status: Can't open connection.")
        GUICtrlSetBkColor($Status, 0xFF0000)
    Else
        GUICtrlSetData($Status, "Status: Connected.")
        GUICtrlSetColor($Status, 0x34DF00)
    EndIf
EndFunc

I'ts build in at line 94

Mayby someone could help me and find whats wrong.

AlmarM

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Nobody?

I doon't know anything about SQL, but the way you have used _MySQLConnect in the function _Connect is nothing like the way you used it in the script that worked, so surely you should be able to start with it the same in the function and then change a bit at a time and see where it goes wrong.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I doon't know anything about SQL, but the way you have used _MySQLConnect in the function _Connect is nothing like the way you used it in the script that worked, so surely you should be able to start with it the same in the function and then change a bit at a time and see where it goes wrong.

Hmm, ill try. Thanks for the info.

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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
 Share

  • Recently Browsing   0 members

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