Hi all. I'm having a few problems with my game's login system. I am currently using CattleRustler's MySQL plugin, IanM's Hash MD5() function, and a new plugin which I am beta testing called the X Plugin.
If someone could take the time to help, I would greatly appreciate it!
Here's the code:
global host$
global user$
global pass$
global db$
global tbl$
global colname$
global ulogin$
global handshake
handshake = 1
if handshake=1
host$="myhost"
user$="myuser"
pass$="mypass"
db$="mydb"
tbl$="users"
colname$="user_name"
colname2$="pwd"
make object cube 100,10
autocam off
window = X Make Widget Window(screen width()/2, 300)
X Set Widget Text window, "MySQL 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,300/2
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)
load image "cursor.png", 1
global logintries
logintries = 5
X TEXT FIELD SET LIMIT user,32
X TEXT FIELD SET LIMIT pass,32
X TEXT FIELD PASSWORD ON pass
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
if connect = 1
conn = mysql_connect(host$,user$,pass$,db$)
if conn
`SELECT column_name(s) FROM table_name WHERE column_name operator value
remstart
$existing= "select * from CSLE_User where Username = '$username'";
$exist=mysql_query($existing) or die (mysql_error());
$num=mysql_numrows($exist) or die (mysql_error());
remend
renderquery$ = "SELECT `"+colname$+"` AND `"+colname2$+"` FROM `"+tbl$+"` WHERE `"+colname$+"` = "+chr$(34)+X Get Widget Text$(user)+chr$(34)+" AND `"+colname2$+"` = "+chr$(34)+Hash MD5(X Get Widget Text$(pass))+chr$(34)
`msgbox("WARNING!","Renderquery="+renderquery$,MBOK)
query=mysql_query(renderquery$)
rowcount=mysql_numrows()+1
msgbox("WARNING!","rowcount:"+str$(rowcount),MBOK)
result$=mysql_result(query,colname$)
`$r=mysql_query("SELECT * FROM table"); $num_results = mysql_num_rows($r); for($i=0; $i<$num_results; $i++) { $arr = mysql_fetch_array($r); print_r($arr); }
`$r=mysql_query(query)
`num_results$ = mysql_num_rows(1,"full_name")
ulogin$ = X Get Widget Text$(user)
upass$ = X Get Widget Text$(pass)
if rowcount>0
for i=0 to MySQL_GetColumnsUpperBound()
num_results$ = MySQL_GetColName(i, colname$)
if ulogin$=num_results$
`print num_results$
`sync
`print "Members="+str$(MySQL_GetColumnsUpperBound()+1)
`sync
msgbox("AUTHENTICATED!","Members="+str$(MySQL_GetColumnsUpperBound()+1), MBOK)
msgbox("AUTHENTICATED!",num_results$,MBOK)
connect = 0
exit
else
if ulogin$<>num_results$ or upass$<>X Get Widget Text$(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)
endif
connect = 0
exit
endif
endif
next i
endif
endif
endif
until ulogin$<>"" and ulogin$=num_results$
delete object 100
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)<>""
connect = 1
else
` Let the GUI system handle the event
X Delegate Event
connect = 0
endif
endwhile
` Update the system
Update X
paste image 1, X Get Mouse X(), X Get Mouse Y(), 1
X Set Widget Text tries, "tries: "+str$(logintries)
sync
until ulogin$<>"" and ulogin$=num_results$
the above is based on THIS code to keep it from reading an empty string:
<?php
include_once("connect.php");
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$existing= "select * from CSLE_User where Username = '$username'";
$exist=mysql_query($existing) or die (mysql_error());
$num=mysql_numrows($exist) or die (mysql_error());
if($num != 0)
{
echo "<center><p>computer Says No</p></center>";
}
else
{
echo "<center><p>Test Wins</p></center>";
}
?>
I basically need to know how to get it to stop giving me this error:
Warning: `Unknown column `testuser` in WHERE clause`
I also need to know how to make it stop giving me THIS error as well using something that counts the number of rows and makes sure they are > 0 before calling mysql_query():
Warning: `There is no row at position 1`
The 1st error happens if you take out the chr$(34)'s in the renderquery$ clause
The 2nd error happens if you leave the chr$(34)'s in the renderquery$ clause
The query is called like this, and the row count is checked like this:
renderquery$ = "SELECT `"+colname$+"` AND `"+colname2$+"` FROM `"+tbl$+"` WHERE `"+colname$+"` = "+chr$(34)+X Get Widget Text$(user)+chr$(34)+" AND `"+colname2$+"` = "+chr$(34)+Hash MD5(X Get Widget Text$(pass))+chr$(34)
`msgbox("WARNING!","Renderquery="+renderquery$,MBOK)
query=mysql_query(renderquery$)
rowcount=mysql_numrows()+1
msgbox("WARNING!","rowcount:"+str$(rowcount),MBOK)
result$=mysql_result(query,colname$)
`$r=mysql_query("SELECT * FROM table"); $num_results = mysql_num_rows($r); for($i=0; $i<$num_results; $i++) { $arr = mysql_fetch_array($r); print_r($arr); }
`$r=mysql_query(query)
`num_results$ = mysql_num_rows(1,"full_name")
ulogin$ = X Get Widget Text$(user)
upass$ = X Get Widget Text$(pass)
if rowcount>0
EDIT:
Here are the functions:
function mysql_numrows()
rowcount=MySQL_GetRowsUpperBound()
endfunction rowcount
`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_num_rows(Oldstr as integer, delim as string)
result$=MySQL_GetWholeRow(Oldstr,delim)
set cursor 0,0
For iLoop = 0 To Oldstr
print MySQL_GetWholeRow(iLoop, "*")+chr$(13)+chr$(10)
sync
Next iLoop
endfunction result$
function mysql_result(row,field$)
result$ = mysql_getrowdatabycolname(row,field$)
endfunction result$
function mysql_connect(host$,user$,pass$,base$)
mySQL_Init
conn$ = "DRIVER={MySQL ODBC 5.1 Driver};SERVER="+host$+";DATABASE="+base$+";UID="+user$+";PASSWORD="+pass$+";OPTION=3;"
con = mysql_setconnection(conn$)
endfunction con
function mysql_query(query$)
rows = mysql_runstatement(query$)
row = row+ 1
endfunction row
Thanks for reading!
CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/