Hello I have a registration form mysql need to add code to detect if the user exists. The existence if it should show the window (alredy registered user)
code:
Imports MySql.Data.MySqlClient
Public Class Form2
'create a public function and set your MySQL Connection .
Public Function mysqlconnection() As MySqlConnection
'return new connection.
Return New MySqlConnection("Server=xxx;User ID=xx;Password=xx;Database=xx")
End Function
'pass the value of mysqlconnection() as MySQL connection to con.
Public con As MySqlConnection = MySqlConnection()
'declaring the variables string
Public sql As String
Public result As String
'declaring the classes
Dim cmd As New MySqlCommand
Public dt As New DataTable
Public da As New MySqlDataAdapter
Public Sub create(ByVal sql As String)
Try
'open the connection
con.Open()
'set your command
With cmd
'holds the data to be executed
.Connection = con
.CommandText = sql
'execute the data
result = cmd.ExecuteNonQuery
'coditioning the result whether succesfull or failed when it is executed.
If result = 0 Then
'the execution of data is failed
MsgBox("Registration failed!")
Else
'the executed data is succesfull
MsgBox("You are now registered.")
End If
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
'put the string value to sql
sql = "INSERT INTO `users` (`email`, `username`, `Pass` ) VALUES ('" _
& txtemail.Text & "','" & txtuser.Text & "','" & txtpass.Text & "')"
'call your sub name and put the sql in the parameters list.
create(sql)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class