mysql - Can't Insert multiple rows using two forms at same page -
this form page form.html
<html> <head> </head> <body bgcolor="blue"> <table> <form action="masemp12ad.jsp" method="post"> <tr><th colspan="2" bgcolor="#c0c0c0">employee referees</th></tr> <tr><td>name:</td><td><input type="text" name="name" maxlength="30"> </td></tr> <tr><td>residential address:</td><td><textarea name="add" rows="10" cols="30"></textarea></td></tr> <tr><td>phone no:</td><td><input type="text" name="no" maxlength="30"></td></tr><tr><td></td><td></td></tr> <tr><td>name:</td><td><input type="text" name="name" maxlength="30"></td></tr> <tr><td>residential address:</td><td><textarea name="add" rows="10" cols="30"></textarea></td></tr> <tr><td>phone no:</td><td><input type="text" name="no" maxlength="30"></td></tr> <tr><td><input type="submit" name="sub" value="save"></td><td><a href="second" style="color: red;text-decoration:none;align:right;">close</a></td></tr> </form> </table> </body> </html>
this jsp page having insert code masemp12ad.jsp
<%@page import="java.sql.*,java.util.*"%> <% string name[]=request.getparametervalues("name"); string add[]=request.getparametervalues("add"); string no[]=request.getparametervalues("no"); try{ class.forname("com.mysql.jdbc.driver"); connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/login", "root", ""); statement st=con.createstatement(); for(int p=0;p<2;p++){ int i=st.executeupdate("insert emp_referees(name,add1,no) values('"+name[p]+"','"+add[p]+"','"+no[p]+"')"); response.sendredirect("masemp12.jsp"); } } catch(exception e){ system.out.print(e); e.printstacktrace(); } %>
i want insert 2 forms data in 2 rows, can't. in table have 3 columns: (name,add1,no). need store these 2 forms data 2 rows.
Comments
Post a Comment