inserting data from radio buttons to database

inserting data from radio buttons to database

View Answers

September 16, 2009 at 2:40 PM

Hi Friend,

Try the following code:

1)radioButton.jsp:

<%@page import="java.sql.*"%>
<html>
<form method="post" action="answers.jsp">
<table>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from question");
int i=0;
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><input type="hidden" name="quid" value="<%=rs.getString(1)%>"><td><input type="radio" value="Poor" name="radio<%=i%>"/>Poor</td><td><input type="radio" value="Average" name="radio<%=i%>"/>Average</td><td><input type="radio" value="Good" name="radio<%=i%>"/>Good</td></tr>
<% i++;
}
%>
<tr><td><input type="Submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)answers.jsp:

<%@page import="java.sql.*"%>
<%
String id[] =request.getParameterValues("quid");
if(id !=null) {
for(int i=0;i<id.length;i++) {
System.out.println(id[i]);
}
}
String option[]= new String[5];
for(int i=0;i<5;i++){
option[i]=request.getParameter("radio"+i);
System.out.println(option[i]);
}
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st=conn.createStatement();
for(int j=0;j<5;j++){
String optionValue=option[j];
String qid=id[j];
System.out.println("update question set phone='jhgfhg' where questionid=1");
st.executeUpdate("update question set options='"+optionValue+"' where questionid='"+qid+"'");
}

out.println("Inserted Successfully");
}
catch(Exception e){
out.println(e);
}
%>

Thanks

March 31, 2013 at 8:31 PM

but using the above code it only displays the last value. my 1st page is <% try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sim?"+"user=root&password=yes");

String n[]=new String[50];
            String a[]=new String[50];
            String id[]=new String[50];
                int c=0,i=0;
                String s=null;
                String s1=request.getParameter("c_id");
                Statement st1=(Statement)con.createStatement();
                out.println("<br>");
                out.println("class");

                out.println(s1);
                out.println("<br>");                                   
                PreparedStatement pstmt=con.prepareStatement(" SELECT * FROM student, student_class WHERE student.s_id = student_class.s_id AND c_id = ? ");
                 pstmt.setString(1,s1);
                  ResultSet rs2= pstmt.executeQuery();
                    while(rs2.next())
                     {
                           s=rs2.getString("s_id");
                           out.println("Name: ");
                           String s2=rs2.getString("fname");
                          String s3=rs2.getString("mname");  
                            String s4=rs2.getString("lname");

                            out.println(s);                                                                                                              
                            out.println(s2);
                            out.println(s3);
                            out.println(s4);

                            n[c]=s; 
                            out.println("<br>"); 

                  out.println("---------------------");
                c++;
            %>



            <form name="stu_class" method="post" action="stu_class1.jsp" >
                                 <table>
                                     <tr>
                                     <br><input type="hidden" name="c_id" value="<%=s1%>"/>
                             PROMOTED<INPUT type=radio name="radio<%=i%>" value="p" request>
                         NOT PROMOTED:<INPUT type=radio name="radio<%=i%>" value="f" checked="true">
                              <td style="padding-top:2%">
                            </form>
                             <input type="hidden" name="c" value="<%=c%>"/>
                              </table>
                              <% 
                                        i++;
                     }  
                  session.setAttribute("n",n);

              %>     

                             <TD align="right" style="padding-right:20%">
                             <INPUT type="submit" value="Update" name="submit" >


            <% }
           catch (SQLException e) 
          {
              throw new ServletException("Servlet Could not display records.", e);
          }




and my 2nd page is
try 
         {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sim?"+"user=root&password=yes");
            String s1=request.getParameter("c_id");
          String s=request.getParameter("s_id");
            String c=request.getParameter("c");
            String id[]=new String[50];
            int t=Integer.parseInt(c);
            out.println(c);
           out.println(s);
            out.println(s1);
         //  String values[] =(String [])request.getParameterValues("a");
           String val[]=(String [])session.getAttribute("n");
           //  out.println(values[0]);
             //  out.println(val[0]);
                            for(int j=0;j<t;j++)
                {
                    out.println("<br>");
                     out.println(val[j]);       
                 }
          for(int i=0;i<t;i++)
          {
              out.println("test"); 
           id[i]=request.getParameter("radio"+i);
          out.println(id[i]);
            }
                       }
        catch (SQLException e) 
          {
              throw new ServletException("Servlet Could not display records.", e);
          }
                    %>

the problem is it displays only the last value of radio button









Related Tutorials/Questions & Answers:
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem... of radio buttons. the feedback.jsp should look like same as follows: Please... as per his choice. when user completes all the selection of radio buttons and he
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has the option field as options. but it is option in the table,so i changed
Advertisements
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons and when i click on delete button. it points to the answer.jsp. answer.jsp
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration... for each data cloumn ..at the time of end of the query... PLz see my code and point my
radio buttons
radio buttons  write a program to create an applet button which has a list of radio buttons with titles of various colours.set the background colour... has a list of radio buttons with titles of various colors and a button
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int... of various rows from database in labels by clicking previous and next
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int... of various rows from database in labels by clicking previous and next
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table... of a table,that is none of the data which i tried to enter into database by using
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
3 RADIO BUTTONS
3 RADIO BUTTONS  3 RADIO BUTTONS USING ALSO ONE RADIO CLICKING HOW TO PROCESS OF NEXTPAGE
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... information from database the i want to show cash radio button checked.How can i do... database and according to that i want to check the cash cheque radio button
selecting data from database
selecting data from database  how to select data from database using Dao in struts   Hi, You have to load the data from database using hibernate and send the data in a Java file object to jsp page.ADS_TO_REPLACE_1
Inserting data from the HTML page to the database
Inserting data from the HTML page to the database... program in which we are going to insert the values in the database table from...() method of the PrintWriter class. We can insert the data in the database only
retrive data from database
retrive data from database   hi.. i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in database access sheet i want to view it at any another
retrive data from database?
retrive data from database?  hellow i have a database sheet name as db1. it's contain sixty(60) sn,name ,rollno(primary key),father's name etc... from db1 and enter value in text box according there name,rollno and save
Radio Buttons - Java Beginners
Radio Buttons  Hello Sir, How to create the code for the password... the radion buttons in display the same page in jsp.I need only how to make the question and answer page using the radio buttons.please help me to solve
fetch data from database in javascript
fetch data from database in javascript   How to fetch data from database in JavaScript when it is a leap year
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
Selecting a radio button in jquery autocomplete from database value
Selecting a radio button in jquery autocomplete from database value  I can get the data from the database using PDO to my jquery.js file. How do I... radio button? Here is the pertinent code: $("#name").autocomplete
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
retreive integer data from database
retreive integer data from database  i made a table named result... and two buttons "ok" and "cancel" i want to take input from textfield...=lalit&database=mydb"); String url="select marks from student where rollno
GWT -- retrive the data from Database
GWT -- retrive the data from Database  the user can create an event. In the create page, we have three buttons. Save as draft, preview and save and post buttons. Once the user entered all the datas and if he clicks the Preview
Radio Buttons in Jsp - JSP-Servlet
Radio Buttons in Jsp  Hi, i have a page in which there are lot of radio buttons [IMG]http://i38.tinypic.com/jzi6vc.jpg[/IMG] see the above picture..." depending on the value in the String radio button has to be checked. How to do
delete data from database - SQL
delete data from database  HOw to delete specific data from table> I want to delete one record from database. Thnx  Hi friend, -------------------------------------------- Visit for more information
To retrive data from database - Struts
To retrive data from database  How to get values ,when i select a select box in jsp and has to get values in textbox automatically from database? eg... come to jsp page automatically from database
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my database is text and all others are of currency data type. If i enter 0 or null value
retrieve data from database with hyperlink
retrieve data from database with hyperlink  sir....i have one table called 'name' having two values i have to retrieve those data with a hyperlink and show in browser and if we click hyperlink its shows his sub categories....how
Inserting Data In Database table using Statement
Inserting Data In Database table using Statement... to insert the data in the database from our java program in the table stored... of the PrintWriter class. We can insert the data in the database only and only
Inserting Data into mysql - SQL
Inserting Data into mysql  My sincere apologize for this post. I... into the SQL category though under php. I need help with reading from a csv file (using php)and inserting the details in a mysql database. Lets take for instance
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
Getting Textbox data from database
data from database and display it on the textboxes. <%@page language="java...Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown
Getting Textbox data from database
;Here is a jsp code that retrieves data from database and display...Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... from the dropdown, related data will get displayed on the textboxes. Here we have
Database Scrolling Buttons
Database Scrolling Buttons  Sir, I have two button "Next" and "Previous". I'am able to retrieve data from database but I don't understand as to how display data on next and previous button clicks. Please help me out
inserting data into datafields
inserting data into datafields  I was raised with a query.... there is a button, on click on it....... few fields regenerates and the details entered there should be inserted into Database Number of times we click that button
Spring 3.2 MVC insert and retrieve blob from the database
In this section, you will learn about inserting and retrieving blob from the database
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS - Struts
for check boxes and radio buttons and for submit buttons. i have a jsp page which... check boxe values and radio button values to be saved in Data Base. pls help me...WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS 
Retrieval data from database against timer
Retrieval data from database against timer  Please send me a sample timer code which retrieve data from the database against timer in JSP
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
how to use bean to retrieve data from database
how to use bean to retrieve data from database  how to use bean to retrieve data from database   poda sendru
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
data retrival from database throw simple jsp..
data retrival from database throw simple jsp..  We can retrieve the the data from data base simple jsp page: Jsp Page:retrive.jsp <... operaion using checkbox Or radio button...From G RameshNaidu catch
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row

Ads