2

I'm trying to execute this query:

String req="INSERT INTO`fos_user`(`addressmailperso`,`pays`,`job`,`sexe`, `addressjob`,`skills`,`description`) VALUES (?,?,?,?,?,?,?) WHERE username='"+Apptest.current+"';";

this error occured: Syntax error near 'WHERE username ='fayrouz''in line 1.

Ousmane D.
56.6k8 gold badges101 silver badges134 bronze badges
asked Mar 25, 2017 at 17:33
3
  • using binding instead of quoating Commented Mar 25, 2017 at 17:36
  • 3
    There is no WHERE in a standard INSERT statement. You probably need an UPDATE statement instead. Commented Mar 25, 2017 at 17:38
  • Either use update or do not use where. Commented Mar 25, 2017 at 17:44

1 Answer 1

1

In insert there is not where so you should use

String req="INSERT INTO fos_user (addressmailperso,pays,job,sexe, addressjob,skills,description) VALUES (?,?,?,?,?,?,?)";

could be you need an update

 String req="UPDATE `fos_user`
 set `addressmailperso` = ? 
 ,`pays` = ? 
 ,`job` =? 
 ,`sexe` = ? 
 , `addressjob` =?
 ,`skills` = ? 
 ,`description` =? 
 WHERE username='"+Apptest.current+"';";
answered Mar 25, 2017 at 18:05
Sign up to request clarification or add additional context in comments.

2 Comments

I changed the query to : " UPDATE fos_user SET addressmailperso = ? , pays = ? ,job = ?, sexe = ?, addressjob = ?, skills = ? , description = ? WHERE username = " +Apptest.current; But I still have an error: Field 'fayrouz' unknown in where clause. Btw, Apptest.current is a variable that contains the username of the current user of the application wich is Fayrouz.
@FayrouzOuerghi you must wrap the Apptest.current with single quotes like in my sample code. in your code (the code you provided in comment) you missed the single quote. If you don't use quote around the var the name is assumed as column name and not as a literal value .. so look how the single quotes are placed in req string

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.