|
-
Feb 28th, 2009, 06:06 AM
#1
Thread Starter
New Member
Messenger Login Problem?
Hi, im new to the forum so i hope i dont do anything wrong lol.
ok lets get to the point im making an instant messenger with MySQL not flatfile or ini, the messenger consists of a server and a client. ok.
here is my function .bas
Code:
Public Function login(name As String, pass As String, user As Integer) As Integer
Dim filepass As String
Dim blist(200) As String
Dim lsti As Integer
Dim maxlsti As Integer
lsti = 0
If MySQLExists("SELECT * FROM users WHERE username = '" & name & "'") = True Then
filepass = MySQLQuery("SELECT password FROM users WHERE username = '" & name & "'")
Else
frmServer.Server(user).SendData "No user exists"
Exit Function
End If
If pass = filepass Then
'frmUsers.lstUsers.AddItem (name)
frmServer.lstUsers.AddItem name
lusers(userin) = name
userin = userin + 1
frmServer.Server(user).SendData ("Loged in" & vbCrLf)
linus(user) = name
linus(user + 1) = "end"
MySQLQuery ("UPDATE users SET list = '" & blist(lsti) & "' WHERE username = '" & name & "'")
lsti = lsti + 1
While lsti > maxlsti
frmServer.Server(user).SendData blist(maxlsti) & vbNewLine
maxlsti = maxlsti + 1
Wend
frmServer.Server(user).SendData ("Done" & vbNewLine)
End If
If pass <> filepass Then
frmServer.Server(user).SendData ("Wrong password" & vbCrLf)
End If
End Function
ok its the filepass. if you login with no password it works but if u use "the correct password" it dosent.
My question is why?
please help,
Kind Regards,
Nick
-
Feb 28th, 2009, 06:19 AM
#2
Re: Messenger Login Problem?
Hello, and welcome to vbForums!
if you login with no password it works but
The reason is could be much more simple than you think. The filepass is empty all the times!
Can you please show to us, the MySQLQuery() method? Maybe you just use it in the wrong order, that is causing the value 'filepass' will not contain the password never.
ps: A quick tip. Use the VB6 ide window, to intent your code, by using the TAB button, that helps to the others to read your code.
-
Feb 28th, 2009, 06:27 AM
#3
Thread Starter
New Member
Re: Messenger Login Problem?
Yes Sure..
A Mysql Query is ran like this.
vb6 Code:
MySQLQuery("SELECT * FROM tablehere WHERE username = '" & name & "'")
-
Feb 28th, 2009, 06:42 AM
#4
Re: Messenger Login Problem?
I meand, can you show us the whole method? I have a hard feeling that the records should be fetched by using some other methods, but you cant simply get it by executing and waiting for a return value.
-
Feb 28th, 2009, 06:52 AM
#5
Thread Starter
New Member
Re: Messenger Login Problem?
you meen the whole login method?
-
Feb 28th, 2009, 07:05 AM
#6
Re: Messenger Login Problem?
I would like to see the code content of the MySQLQuery() function 
Or it would be better if you can attach here the module/class that you use to communicate with the mysql server.
-
Feb 28th, 2009, 07:12 AM
#7
Thread Starter
New Member
Re: Messenger Login Problem?
vb6 Code:
Global QueryResults As String
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.command
Dim TempData As String
Public Function MySQLConnect()
On Error GoTo mysqlerror
cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=localhost;" _
& "DATABASE=chat;" _
& "UID=root;" _
& "PWD=;" _
& "OPTION=3"
cn.Open
rs.ActiveConnection = cn
Exit Function
mysqlerror: MsgBox (Err.Description), vbCritical, "MySQL Error (000601)"
End
End Function
Public Function MySQLQuery(Query As String) As String
If rs.State = adStateOpen Then
rs.Close
End If
On Error Resume Next
rs.Open Query
MySQLQuery = rs.GetString
rs.Close
MySQLQuery = Mid(MySQLQuery, 1, Len(MySQLQuery) - 1)
Form3.StatusBar1.SimpleText = Query
Exit Function
errhandle:
MsgBox (Err.Description)
End Function
Public Function MySQLWrite(Query As String)
If rs.State = adStateOpen Then
rs.Close
End If
On Error Resume Next
rs.Open Query
Exit Function
errhandle:
MsgBox (Err.Description)
End Function
Public Function MySQLDelete(Query As String)
On Error Resume Next
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open Query
Exit Function
errhandle:
If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
End Function
Public Function MySQLCreate(Query As String)
On Error Resume Next
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open Query
Exit Function
errhandle:
If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
End Function
Public Function MySQLExists(Query As String) As Boolean
On Error Resume Next
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open Query
If rs.State = adStateClosed Then
MySQLExists = False
Exit Function
End If
If rs.EOF = False Then
MySQLExists = True
Else
MySQLExists = False
End If
rs.Close
Exit Function
errhandle:
If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
End Function
and i know about the
errhandle:
MsgBox (Err.Description)
-
Feb 28th, 2009, 07:20 AM
#8
Re: Messenger Login Problem?
Code:
Public Function MySQLQuery(Query As String) As String
If rs.State = adStateOpen Then
rs.Close
End If
On Error Resume Next
rs.Open Query
MySQLQuery = rs.GetString
rs.Close
MySQLQuery = Mid(MySQLQuery, 1, Len(MySQLQuery) - 1)
Form3.StatusBar1.SimpleText = Query
Exit Function
errhandle:
MsgBox (Err.Description)
End Function
Because, you are use the On Error Resume Next cause, the errhandle: will not get executed never. That is might be the reason, the result is an empty string, because an error occurs, but your code is simply skip the error, and returns the null string. It would be beter, to modify it to:
On Error Goto errHandle:
..to see what error happens.
-
Feb 28th, 2009, 07:25 AM
#9
Thread Starter
New Member
Re: Messenger Login Problem?
ok i placed the errHandle in before, but removed it because everytime i ran a query i got an error wait a sec ill tell you what the error said if it helps.
-
Feb 28th, 2009, 07:36 AM
#10
Re: Messenger Login Problem?
While you are designing your application, it would be better to NOT to use any "on error resume next", it is will simply foolish you, so you will never dont know what error happens, because of a typo in an sql query, or just executing improper queries on tables that have no fields available.
Use on error resume next in case, in your final product, when you are absolutely sure that everythings is works as well, and will never fail in no case, or it is just better to hide an error that may happens in several circumstances that you cant avoid..
-
Feb 28th, 2009, 08:25 AM
#11
Thread Starter
New Member
Re: Messenger Login Problem?
ok my error about the password thing is fixed but my server gets an error:
Operation is not allowed when the object is closed.
-
Feb 28th, 2009, 09:54 AM
#12
Re: Messenger Login Problem?
Remove the On Error Goto.. 's to see where the error happens, and you can also use debug.print to see what values are missing. Probably, your ADO have already closed the connection, but you are still try to access resources, or execute queries. That is could be the reason to raise an error like you got there.
-
Feb 28th, 2009, 10:25 AM
#13
Thread Starter
New Member
Re: Messenger Login Problem?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|