Results 1 to 13 of 13

Thread: Messenger Login Problem?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    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

  2. #2
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    Re: Messenger Login Problem?

    Yes Sure..


    A Mysql Query is ran like this.

    vb6 Code:
    1. MySQLQuery("SELECT * FROM tablehere WHERE username = '" & name & "'")

  4. #4
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    Re: Messenger Login Problem?

    you meen the whole login method?

  6. #6
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    Re: Messenger Login Problem?

    vb6 Code:
    1. Global QueryResults As String
    2. Dim cn As New ADODB.Connection
    3. Dim rs As New ADODB.Recordset
    4. Dim cmd As New ADODB.command
    5. Dim TempData As String
    6. Public Function MySQLConnect()
    7. On Error GoTo mysqlerror
    8. cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
    9.            & "SERVER=localhost;" _
    10.            & "DATABASE=chat;" _
    11.            & "UID=root;" _
    12.            & "PWD=;" _
    13.            & "OPTION=3"
    14. cn.Open
    15. rs.ActiveConnection = cn
    16. Exit Function
    17. mysqlerror: MsgBox (Err.Description), vbCritical, "MySQL Error (000601)"
    18. End
    19. End Function
    20. Public Function MySQLQuery(Query As String) As String
    21. If rs.State = adStateOpen Then
    22. rs.Close
    23. End If
    24. On Error Resume Next
    25.  
    26. rs.Open Query
    27. MySQLQuery = rs.GetString
    28. rs.Close
    29. MySQLQuery = Mid(MySQLQuery, 1, Len(MySQLQuery) - 1)
    30. Form3.StatusBar1.SimpleText = Query
    31. Exit Function
    32. errhandle:
    33. MsgBox (Err.Description)
    34. End Function
    35. Public Function MySQLWrite(Query As String)
    36. If rs.State = adStateOpen Then
    37. rs.Close
    38. End If
    39. On Error Resume Next
    40.  
    41. rs.Open Query
    42. Exit Function
    43. errhandle:
    44. MsgBox (Err.Description)
    45. End Function
    46. Public Function MySQLDelete(Query As String)
    47. On Error Resume Next
    48. If rs.State = adStateOpen Then
    49. rs.Close
    50. End If
    51. rs.Open Query
    52. Exit Function
    53. errhandle:
    54. If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
    55. End Function
    56. Public Function MySQLCreate(Query As String)
    57. On Error Resume Next
    58. If rs.State = adStateOpen Then
    59. rs.Close
    60. End If
    61. rs.Open Query
    62. Exit Function
    63. errhandle:
    64. If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
    65. End Function
    66. Public Function MySQLExists(Query As String) As Boolean
    67. On Error Resume Next
    68. If rs.State = adStateOpen Then
    69. rs.Close
    70. End If
    71. rs.Open Query
    72. If rs.State = adStateClosed Then
    73. MySQLExists = False
    74. Exit Function
    75. End If
    76. If rs.EOF = False Then
    77. MySQLExists = True
    78. Else
    79. MySQLExists = False
    80. End If
    81. rs.Close
    82. Exit Function
    83. errhandle:
    84. If frmMain.MySQL.Value = 1 Then frmMain.QueryError.Text = Err.Description
    85. End Function

    and i know about the

    errhandle:
    MsgBox (Err.Description)

  8. #8
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    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.

  10. #10
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

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

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    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.

  12. #12
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    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.

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    11

    Re: Messenger Login Problem?

    Ok Thanks Ill Try That.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width