Question:
help me identify the mistake please!!!urgent!!?
braich_gal
2006-08-02 08:38:35 UTC
query = "INSERT INTO MembersInfo ("Name,User Name,Password,Confirm Password, Password hint, Address, City, Postal Code, State, Country, [Home No:],[Handphone No:], SMS Alerts, E-mail Address") VALUES (" & "'" & txtName.Text & "'" & "," & "'" & txtUserName.text & "'" & "," & "'" & txtPassword.text & "'" & "," & "'" & txtConfirmPassword.text & "'" & "," & "'" & txtPasswordHint.text & "'" & "," & "'" & txtAddress.text & "'" & "," & "'" & txtCity.text & "'" & "," & "'" & txtPostalCode.text & "'" & "," & "'" & txtState.text & "'" & "," & "'" & txtCountry.text & "'" & "," & "'" & txtHome.text & "'" & "," & "'" & txtHandphone.text & "'" & "," & "'" & txtEmail.text & "'" & ")"
error message: end of statement expected...where?HELP PLEASE
Six answers:
mainstrike
2006-08-02 09:05:11 UTC
There are a couple issues here.

- As someone pointed out, there are many quotes and it gets confusing.

- Field names with special characters in them require a binding around them to indicate the full field name.

- Without knowing the way your database is structured, this would be very challenging. For example, is your User Name field really User Name? If so, it must be quoted because of the space.



What I am doing below is removing some unnecessary quotes and adding square brackets to delimit the field name correctly.



query = "INSERT INTO MembersInfo ([Name],[User Name],[Password], [Confirm Password], [Password hint], [Address], [City], [Postal Code], [State], [Country], [Home No:], [Handphone No:], [SMS Alerts], [E-mail Address]) VALUES ('" & txtName.Text & "', '" & txtUserName.text & "', '" & txtPassword.text & "', '" & txtConfirmPassword.text & "', '" & txtPasswordHint.text & "', '" & txtAddress.text & "', '" & txtCity.text & "', '" & txtPostalCode.text & "', '" & txtState.text & "', '" & txtCountry.text & "', '" & txtHome.text & "', '" & txtHandphone.text & "', '" & txtEmail.text & "');"



Please modify your question to also include the structure of your table so that I can ensure accuracy of the query. All these modifications assume you are using Microsoft Access. They may not work under other SQL databases.
aargre
2006-08-02 08:55:54 UTC
try "INSERT INTO MembersInfo (Name,User Name,Password,Confirm Password, Password hint, Address, City, Postal Code, State, Country, [Home No:],[Handphone No:], SMS Alerts, E-mail Address) VALUES ('" & txtName.Text & "','" & txtUserName.Text & "','" & txtPassword.Text & "','" & txtConfirmPassword.Text & "','" & txtPasswordHint.Text & "','" & txtAddress.Text & "','" & txtCity.Text & "','" & txtPostalCode.Text & "','" & txtState.Text & "','" & txtCountry.Text & "','" & txtHome.Text & "','" & txtHandphone.Text & "','" & txtEmail.Text & "')"
gpashtun
2006-08-02 08:58:57 UTC
your commas look correct to me. You have the same amount of values to column names. Try putting a semi-colon at the end of the statement before you hit enter. ;



There could be other issues... hard to tell without having access to the database. Your entries look weird and your column names seem weird as well (the ones with the brackets). The error you're getting is most commonly referring to a missing semi-colon at the end of a statement.
John J
2006-08-02 09:09:43 UTC
first off, there should be no quotes around your field names section (back tics ` around each one if you want, but not quotes around the whole section. EDIT - I didn't note the spaces in some of your field names, those you will definately need the back tics around.



Next you need to comma seperate each of the values being inserted into the fields in your VALUES(...) section



And use a different type of quote mark in the query than around the query. I.e. query="INSERT INTO table VALUES ('a','b')"; not query="INSERT INTO table VALUES ("a","b")"; the commas in the query are seen to be the end of the programming statement.
Sean I.T ?
2006-08-02 08:43:29 UTC
In your VALUES I see a bunch of "" "" without any commas separating them. You should make sure you separate each object youre trying to insert into that table.



And you dont need quotes after MembersInfo("

get rid of those quotation marks.



EDIT: If the .text is not declared that means it does not exist. Check your tables and make sure that the reference to that object exists or else it gets confused.
Javy
2006-08-02 08:53:23 UTC
the string at first is not concatenated correctly and you Ar using Fields name that have special characters without the []


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...