我目前遇到了一個問題,我實際上無法解決,我在互聯網上進行了研究,但是我發現的建議只是不提供,爲我工作。嘗試向MySQL中插入數據時,「您的SQL語法有錯誤」
我試圖做一個註冊系統,只是爲了好玩,沒有什麼嚴重的,但我很樂意想知道我做錯了什麼,因爲我大概可以使用這一天。
編輯:我從@Gordon和許多其他的建議解決方案這可能會更加有用,我會考慮嘗試所有的建議。
非常感謝你=)
而且我的代碼:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
mysqlconn = New MySqlConnection
mysqlconn.ConnectionString = "server=localhost;userid=root;password=Emil8250;database=Mysql"
Dim Reader As MySqlDataReader
If TxT_User.Text = "" Or TxT_Pass1.Text = "" Or TxT_Pass2.Text = "" Or TxT_Email.Text = "" Or TxT_SC.Text = "" Then
MsgBox("You need to fill out the required informations above", MsgBoxStyle.Critical)
Else
If TxT_Email.Text.Contains("@") Then
If TxT_Pass2.Text = TxT_Pass1.Text Then
Try
mysqlconn.Open()
Dim Query As String
Query = "INSERT INTO syntax.members (Username, Password, Email, Secret Answer) VALUES ('" & TxT_User.Text & "', '" & TxT_Pass1.Text & "', '" & TxT_Email.Text & "', '" & TxT_SC.Text & "')"
cmd = New MySqlCommand(Query, mysqlconn)
Reader = cmd.ExecuteReader
MsgBox("Account created!", MsgBoxStyle.Information)
mysqlconn.Close()
Catch ex As MySqlException
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally
mysqlconn.Dispose()
End Try
Else
MsgBox("Your Password doesn't match the retyped version", MsgBoxStyle.Critical)
End If
Else
MsgBox("Your email is not valid, please type a valid email address", MsgBoxStyle.Critical)
End If
End If
End Sub
在嘗試執行並在此處共享之前,您可以打印「Query」的內容嗎? – Mureinik
你想要MySQL中的值嗎?我如何將查詢信息完全打印給您? – GuestAnon
雖然沒有直接回答你的問題,但我建議在進一步學習之前,立即擺脫編寫使用字符串連接的VB/SQL代碼的習慣。這是一個巨大的安全漏洞,也是非常糟糕的做法。相反,將參數添加到您的SQL命令。這不僅更安全,而且會產生更強大的代碼。 – Lunster