sql - Insert records into two tables having common column -
i want insert name stud
in foreign key t_id
primary key in table (teacher) want know query that.
insert stud s_id,name,t_id,username,password s_id="+s_id)
this query writing in jsp page...but giving me error
cannot add or update child row: foreign key constraint fails (`userdb`.`stud`, constraint `stud_ibfk_1` foreign key (`t_id`) references `teachers` (`t_id`));
("insert stud(s_id,name,t_id,username,password) values ( " + s_id + "," + name + "," + t_id + "," + username + "," + password + ")")
this correct parameterized insert query syntax.
your query had 2 where clauses written incorrectly, plus values clause not there, plus didn't mention column names explicitly in syntax. hence, query doesn't make sense @ all.
p.s. used dummy data. insert appropriate , relevant data in query. also, assumed parameter names same columns' names. please modify parameters according code if necessary.
Comments
Post a Comment