我目前遇到了一个问题,我实际上无法解决,我在互联网上进行了研究,但是我发现的建议只是不提供,为我工作。尝试向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