Ok it's STARTING to work.
Now I'm having another problem that's making it still crash.
The problem is:
conn = DBRunSQL("SELECT "+connstr$(5)+","+connstr$(6)+" FROM "+connstr$(4)+";")
Which returns:
SELECT user,pwd FROM users;
Here's the code:
Rem Project: network
Rem Created: Tuesday, November 23, 2010
Rem ***** Main Source File *****
sync on
Start X
X Set Target FPS 60
set display mode screen width(),screen height(),screen depth(),1
Type Database_Drivers
name$ as string
EndType
`message box type constants
Global MBOK = 0x0
Global MBOKCANCEL = 0x1
Global MBABORTRETRYIGNORE = 0x2
Global MBYESNOCANCEL = 0x3
Global MBYESNO = 0x4
Global MBRETRYCANCEL = 0x5
Global MBYES = 0x6
Global MBNO = 0x7
Global WMCLOSE = 0x10
Global conn as boolean
Global connect as integer
Global dbtype as integer
Global onlinemode as boolean
onlinemode = 1
dbtype = 0
Global maxdbs=2
Global maxdrivers=100
Global maxservers=100
Global maxstrings=100
Global Drivers as Database_Drivers
global window
global user
global userlabel
global pass
global passlabel
global login
global tries
global usercount
global passcount
global logintries
Dim Servername$(maxservers) as string
Servername$(0) = "Zealous Server"
Servername$(1) = "Kikoa Server"
Servername$(2) = "Test Server"
Servername$(3) = "Test2 Server"
Servername$(4) = "Test3 Server"
Servername$(5) = "Test4 Server"
Dim Drivers$(maxdrivers) as string
Drivers$(0) = "{MySQL ODBC 5.1 Driver}"
Drivers$(1) = "{Microsoft Access Driver (*.mdb)}"
Dim connstr$(maxstrings) as string
host$ as string
base$ as string
user$ as string
pass$ as string
tbl$ as string
dbqueryfile$ as string
dbtype as integer
encrypt$ as string
ID as integer
Name$ as string
Age as integer
Active as boolean
Pie as float
Height as dword
DBErr$ as string
DBStr$ as string
conn as integer
connect as integer
quit as integer
if onlinemode=0
Game_Start()
Game_Update()
else
Login()
endif
Function Game_Start()
Endfunction
Function Game_Update()
do
Update X
sync
loop
Endfunction
Function Login()
window = X Make Widget Window(screen width()/2, 300)
X Set Widget Text window, "Kingdom Of Jewels Login"
X Widget Resize Off window
X Widget Close Box Off window
X Widget Maximize Box Off window
X Widget Minimize Box Off window
X Set Focus Widget window
X Position Widget window, screen width()/4,screen height()/4
X Widget Drag Off window
user = X Make Widget Text Field(window, 145, 10, screen width()/7, 25)
userlabel = X Make Widget Label(window, 110, 10, screen width()/7, 25)
X Set Widget Text userlabel, "User: "
pass = X Make Widget Text Field(window, 145, 45, screen width()/7, 25)
passlabel = X Make Widget Label(window, 107, 45, screen width()/7, 25)
X Set Widget Text passlabel, "Pass: "
login = X Make Widget Button(window, 150, 100, 100, 25)
X Set Widget Text login, "Login"
tries = X Make Widget Label(window, 107, 160, 100, 25)
usercount = X Make Widget Label(window, 175, 170, 100, 25)
passcount = X Make Widget Label(window, 175, 200, 100, 25)
logintries = 0x05
load image "cursor.png", 1
X TEXT FIELD SET LIMIT user,0x20
X TEXT FIELD SET LIMIT pass,0x20
X TEXT FIELD PASSWORD ON pass
If dbtype = 0
connstr$(0) = "localhost"
connstr$(1) = "KOJ_Login"
connstr$(2) = "root"
connstr$(3) = "~Osm0sisG3n0sis"
connstr$(4) = "users"
connstr$(5) = "user"
connstr$(6) = "pwd"
connstr$(7) = "true"
msgbox("","dbtype:"+str$(dbtype),MBOK)
Else
connstr$(2) = "Admin"
connstr$(3) = "pwd"
connstr$(4) = "Table1"
connstr$(5) = "true"
msgbox("","dbtype 2:"+str$(dbtype),MBOK)
Endif
If dbtype=0
msgbox("","SELECT "+connstr$(5)+","+connstr$(6)+" FROM "+connstr$(4)+";",MBOK)
` Run our test SQL Statement
conn = DBRunSQL("SELECT "+connstr$(5)+","+connstr$(6)+" FROM "+connstr$(4)+";")
msgbox("",str$(conn),MBOK)
` If no rows are returned
If conn = 0
Print "No rows matched your query."
Sync
Endif
` How many rows were retrieved
If conn > 0
Print str$(conn)+" rows returned."
Print " "
Sync
Wait 1000
Cls
Endif
` If there was an error
If conn = -1
DBErr$ = DBError()
While Len(DBErr$) > 70
Wait 1000
Print Left$(DBErr$, 70)
Cls
DBErr$ = Right$(DBErr$, Len(DBErr$)-70)
EndWhile
Wait 2000
Print DBErr$
Print " "
Print "Press any key to exit."
Sync
Wait key
Cls
end
Endif
` If there was an error
If conn = -1
DBErr$ = DBError()
While Len(DBErr$) > 70
Wait 1000
Print Left$(DBErr$, 70)
Cls
DBErr$ = Right$(DBErr$, Len(DBErr$)-70)
EndWhile
Wait 2000
Print DBErr$
Print " "
Print "Press any key to exit."
Sync
Wait key
Cls
end
Endif
If conn>0
x0=screen width()/2-Text width("Select A Server")/2
y0=screen height()/2-Text height("Select A Server")/2
Set cursor x0,y0
Print "Select A Server"
Sync
Wait 1000
Cls
For x=0 to 5
inc incr,x
inc pos,10
xwidth1=pos*Text width(Servername$(x))/2-screen width()/4
x1=xwidth1
y1=10
xwidth2=incr*pos*xwidth1
y2=y1
xwidth3=incr*pos*xwidth2
y3=y2
If Servername$(x)<>""
Select x
Case 0
Set cursor x1,y1
Print Servername$(x)
EndCase
Case 1
Set cursor x2,y2
Print Servername$(x)
EndCase
Case 2
Set cursor x3,y3
Print Servername$(x)
EndCase
Case 3
Set cursor x4,y4
Print Servername$(x)
EndCase
Case 4
Set cursor x5,y5
Print Servername$(x)
EndCase
Case 5
Set cursor x6,y6
Print Servername$(x)
EndCase
EndSelect
Endif
Next x
Endif
Endif
If dbtype = 1
conn = DBRunSQL("SELECT * FROM "+connstr$(4)+" ORDER BY ID DESC")
` Retrieve the data from the dataset
If conn > 0
Print "ID Name Age Active Pi Height"
Print "-------------------------------------------------"
For x = 0 to conn-1
ID = DBGetInt32(x, 0)
Name$ = DBGetString(x, 1)
Age = DBGetInt32(x, 2)
Active = DBGetBool(x, 3)
Pie = DBGetFloat(x, 4)
Height = DBGetDword(x, 5)
Print str$(ID)+" "+Name$+" "+str$(Age)+" "+str$(Active)+" "+str$(Pie)+" "+str$(Height)
Next x
Endif
Endif
conn = DBRunSQL("SELECT * FROM "+connstr$(4))
` If no rows are returned
If conn = 0
Print "No rows matched your query."
Sync
Endif
` How many rows were retrieved
If conn > 0
Print
Print str$(conn)+" rows returned."
Print " "
Sync
endif
` if there was an error
If conn = -1
DBErr$ = DBError()
While len(DBErr$) > 70
Print Left$(DBErr$, 70)
DBErr$ = Right$(DBErr$, Len(DBErr$)-70)
endwhile
Print DBErr$
Print " "
Print "Press any key to exit."
sync
Wait key
Cls
End
Endif
Make object cube 100,10
Autocam off
If dbtype=0
query$ = "SELECT * FROM "+connstr$(4)+";"
conn = DBRunSQL(query$)
If conn = 0
Print "No rows matched your query."
Sync
Endif
Endif
Repeat
userlimit=X Text Field Get Limit(user)
If X Get Widget Text$(user)<>""
Dec userlimit,1
Else
Inc userlimit,1
Endif
If userlimit>32 then userlimit=32
If userlimit<0 then userlimit=0
X Set Widget Text usercount,"Chars left:"+str$(userlimit)
passlimit=X Text Field Get Limit(pass)
If X Get Widget Text$(pass)<>""
Dec passlimit,1
Else
Inc passlimit,1
Endif
If passlimit>32 then passlimit=32
If passlimit<0 then passlimit=0
X Set Widget Text passcount,"Chars left:"+str$(passlimit)
If logintries<0 then logintries=0
If logintries>5 then logintries=5
ulogin$ = X Get Widget Text$(user)
upass$ = X Get Widget Text$(pass)
If conn>0
For a=0 to conn-1
result_user$ = DBGetDataByColName(a, connstr$(5))
result_pass$ = DBGetDataByColName(a, connstr$(6))
Msgbox("z",num_results$,MBOK)
If ulogin$=num_results$ and upass$<>num_results$
Msgbox("AUTHENTICATED!",num_results$,MBOK)
conn=0
Exit
Else
If ulogin$<>result_user$ or upass$<>Hash MD5(result_pass$)
Dec logintries,1
Msgbox("WARNING","Invalid username or password!",MBOK)
If logintries>=1
Msgbox("WARNING!","You have: '"+str$(logintries)+"' left to login correctly before your account is locked",MBOK)
Else
If logintries=0
locked=1
Endif
Endif
If locked
Msgbox("WARNING!","Your account has been locked! Please contact the server administrator to have your account unlocked!",MBOK)
conn=0
Exit
Endif
Endif
Endif
Next a
Endif
` Handle some events
While X Event Pending()
` Grab the next event
X Next Event
If X Get Event Widget() = login and X Left Mouse(1) and X Get Widget Text$(user)<>"" And X Get Widget Text$(pass)<>""
conn = mysql_connect(Drivers$(dbtype),dbqueryfile$)
msgbox("",str$(conn),MBOK)
Cls
Set cursor screen width()/2-text width("Handshaking...")/2, screen height()/2-text height("Handshaking...")/2
Print "Handshaking..."
Wait 1000
Sync
Wait 1000
connect=mysql_conn(conn)
msgbox("",str$(connect),MBOK)
Else
` Let the GUI system handle the event
X Delegate Event
Endif
Endwhile
` Update the system
X Set Widget Text tries, "tries: "+str$(logintries)
Update X
Sync
Until ulogin$<>"" and ulogin$=num_results$
Delete object 100
Endfunction
Function mysql_connect(driver$="",dbqueryfile$="")
Select dbtype
//MySQL
Case 0
DBR = DBConnect("DRIVER="+driver$+";SERVER="+connstr$(0)+";DATABASE="+connstr$(1)+";UID="+connstr$(2)+";PASSWORD="+connstr$(3)+";OPTION=3;Encrypt="+connstr$(4)+";")
EndCase
//MDB - User: Admin, Password: pwd
Case 1
DBR = DBConnect("Driver="+driver$+";Dbq="+dbqueryfile$+";Uid="+connstr$(2)+";Pwd="+connstr$(3)+";Encrypt="+connstr$(5)+";")
EndCase
Case Default
DBR = DBConnect("DRIVER="+driver$+";SERVER="+connstr$(0)+";DATABASE="+connstr$(1)+";UID="+connstr$(2)+";PASSWORD="+connstr$(3)+";OPTION=3;Encrypt="+connstr$(4)+";")
EndCase
EndSelect
Select DBR
Case 0
connsuccess = 0
Endcase
Case 1
connsuccess = 1
Endcase
Case Default
connsuccess = -1
Endcase
EndSelect
Endfunction connsuccess
Function die(func as string)
If func<>""
connect=0
Exitfunction
Endif
Endfunction func
Function mysql_error(conn)
DBErr$ = DBError()
Select conn
Case 0
While len(DBErr$) > 70
DBErr$ = right$(DBErr$, len(DBErr$)-70)
Msgbox("WARNING!","error: "+left$(DBErr$, 70),MBOK)
Endwhile
Endcase
Endselect
Endfunction DBErr$
`the actual message box function
Function msgbox(caption as string, msg as string, msgtype as dword)
returnval as dword
load dll "user32.dll", 1
hwnd as dword : hwnd = CALL DLL (1,"GetForegroundWindow")
returnval = call dll(1, "MessageBoxA", hwnd, msg, caption, msgtype)
delete dll 1
Endfunction returnval
Function MySQL_GetColName(RowIndex as integer, Colname as string)
result$=MySQL_GetRowDataByColName(RowIndex, Colname)
Endfunction result$
Function mysql_conn(connect)
welcomemsg$="Welcome to the Server!"
Cls
Set cursor screen width()/2-text width("Handshake Succeeded!")/2, screen height()/2-text height("Handshake Succeeded!")/2
` if connection succeeded
If connect=1
Print "Handshake Succeeded!"
Sync
Wait 2000
Cls
Set cursor screen width()/2-text width("Connected to Database.")/2, screen height()/2-text height("Connected to Database.")/2
Print "Connected to Database."
Set cursor screen width()/2-text width("Press any key to continue.")/2, screen height()/2-text height("Press any key to continue.")/2+20
Print "Press any key to continue."
Print " "
Sync
Wait key
cls
Set cursor screen width()/2-text width(welcomemsg$)/2,screen height()/2-text height(welcomemsg$)/2
Print welcomemsg$
Print
Print
For x=0 to 5
inc ypos,1
Select x
Case 0
connstrtype$="Host: "
Endcase
Case 1
connstrtype$="Database: "
Endcase
Case 2
connstrtype$="User: "
Endcase
Case 3
connstrtype$="Password: "
Endcase
Case 4
connstrtype$="Table: "
Endcase
Case 5
connstrtype$="Encrypt: "
Endcase
Endselect
Set cursor screen width()/2-text width(welcomemsg$)/2,screen height()/2-text height(welcomemsg$)/2+20*ypos
Print connstrtype$+connstr$(x)
Next x
Sync
Wait key
Cls
Endif
` if there was an error
If connect < 1
cls
Set cursor screen width()/2-text width("Handshake failed...")/2, screen height()/2-text height("Handshake failed...")/2
Print "Handshake failed..."
Sync
Wait 1000
Cls
DBErr$ = DBError()
Cls
While len(DBErr$) > 60
Print left$(DBErr$, 60)
Print " "
DBErr$ = right$(DBErr$, len(DBErr$)-60)
Endwhile
If DBErr$ = ""
Print "Error: Unknown"
Print
Else
Print "Error: "
Print DBErr$
Print
Print "Press any key to exit."
Sync
Wait key
Cls
End
Endif
Endif
Endfunction connect
Thanks!
CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!