Question

Ok, I have problem with MySQL insert command. I have 4 variables firstname, lastname, email, password and I want to insert them into my users table.

st.executeUpdate("insert into users(UserFirstName, UserLastName, UserEmail, UserPassword) values ('" + fname + "','" + lname + "','" + email + "','" + pwd + ")");    

When I use the above statement gives me this error;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

st.executeUpdate("insert into users(UserFirstName, UserLastName, UserEmail, UserPassword) values (" + fisrtname + "," + lastname + "," + email + "," + password + ")");

When I use the above statement gives me this error;

Unknown column 'bbb' in 'field list'

PS: 'bbb' is string for fname, I type that for just try.

Was it helpful?

Solution

you missed one single quote after pwd:

st.executeUpdate("insert into users(UserFirstName, UserLastName, UserEmail, UserPassword) values ('" + fname + "','" + lname + "','" + email + "','" + pwd + "')"); 

OTHER TIPS

EDIT: On initial question the '" + user + "' existed, subsequently corrected by the author. See the comments below of the answer.

Note that the INSERT stmt has four columns and five values:

st.executeUpdate("
    insert into users(
        UserFirstName, 
        UserLastName, 
        UserEmail, 
        UserPassword
    ) values (
        '" + fname + "',
        '" + lname + "',
        '" + email + "',
        '" + user + "',
        '" + pwd + "')
    ");

EDIT: Remove the user value from VALUES. And insert more one ' on pwd value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top