I'm writing a program that asks a user to input their username and password into my database on localhost that uses phpmyadmin. I tried following this tutorial on how to do it: https://www.youtube.com/watch?v=jZsTLlFoNuo and I can connect to the Database just fine, I think my problem is my SQL statement. Here is my code for the form:
Imports MySql.Data.MySqlClient
Public Class frmSignup
Dim ServerString As String = "Server=localhost;User Id=;Password=;Database=AccountInfo"
Dim SQLConnection As MySqlConnection = New MySqlConnection
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SQLConnection.ConnectionString = ServerString
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("Successfully connected to DB")
Else
SQLConnection.Close()
MsgBox("Failed to connect to DB")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub SaveAccountInformation(ByRef SQLStatement As String)
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.ExecuteNonQuery()
End With
SQLConnection.Close()
MsgBox("Successfully Registered Account!")
SQLConnection.Dispose()
End Sub
Private Sub btnSignup_Click(sender As Object, e As EventArgs) Handles btnSignup.Click
If txtPasswd.Text = txtPasswd2.Text Then
MessageBox.Show("Passwords Match!")
Dim SQLStatement1 As String = "INSERT INTO `accountinfodb` (`Usernames`, `Passwords`) VALUES ('', '')"
Else
MessageBox.Show("Passwords Do Not Match!")
txtPasswd.Text = Focus()
txtPasswd.Clear()
txtPasswd2.Text = Focus()
txtPasswd2.Clear()
End If
End Sub
End Class
My database is called "Account Information" with my table called "Accounts" which is where I wanted to store their username and password.
So my overall question is, how do I store my information(Username & Password) into phpmyadmin? I've tried looking on Google, but to no avail have I found anything. If anyone could help me succeed that would be awesome, thank you!
EDIT 1
So now I have an error in my SQL Syntax, so I'm about 99% sure it's my SQL Statement in my code that is incorrect when storing the username and password.
Dim SQLStatement1 As String = "INSERT INTO accountinfo(accountinfodb) (`Usernames`, `Passwords`) VALUES ('" & txtPasswd.Text & txtUsername.Text & "')"
Gives me the error:
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
Usernames
,Passwords
) VALUES ('123123')' at line 1
When I type 123 for the username, and 123 for the password.