Results 1 to 4 of 4

Thread: Search My Sql

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    Smile Search My Sql

    can someone please tell me how i can search a mysql database, what i need is for it to search for the username and password and see if they match in the database, i am completley new to mysql, i have through a example managed to connect to the database and disaply it with this:

    VB Code:
    1. Option Explicit
    2.  
    3.   Private cn As New ADODB.Connection
    4.   Private rs As New ADODB.Recordset
    5.   Private cnString As String
    6.   Private sSQL As String
    7.  
    8. Private Sub cmdExecute_Click()
    9.  
    10. On Error GoTo ErrHandler
    11.  
    12.   Dim sTable As String
    13.  
    14.     sTable = "phpbb_users"
    15.    
    16.     cnString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & "*****" & ";PORT=3306;" & _
    17.                     "DATABASE=" & "*******" & ";USER=" & "888888" & ";PASSWORD=" & "*******" & _
    18.                     ";OPTION=3;"
    19.    
    20.     cn.ConnectionString = cnString
    21.     cn.Open
    22.    
    23.    
    24.     If chkQuery.Value <> 1 Then sSQL = "Select * from " & sTable
    25.    
    26.     rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic
    27.    
    28.     Set MSHFlexGrid1.Recordset = rs
    29.  
    30.     Set cn = Nothing
    31.     Set rs = Nothing
    32.     Exit Sub
    33. ErrHandler:
    34.     MsgBox Err.Description, vbCritical
    35.     Resume Next
    36. End Sub

    i dont know if this matters but the field headings are username and user_password, any help or a point in the right direction would bre great

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Search My Sql

    Try this.....

    VB Code:
    1. If chkQuery.Value <> 1 Then
    2. sSQL = "Select * from " & sTable & " WHERE username = '" & username & "' AND user_password = '" & password & "'"
    3.    
    4. rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic
    5.  
    6. 'Now check if user exists
    7. If rs.EOF = True Then
    8. msgbox "User doesn't exist!"
    9.  
    10. else
    11.  
    12.     Set MSHFlexGrid1.Recordset = rs
    13.  
    14. end if
    15.  
    16.     Set cn = Nothing
    17.     Set rs = Nothing
    18.     Exit Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    Re: Search My Sql

    thanks so much, works great

  4. #4
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Search My Sql

    Glad to help

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