my problem is i have an error in my problem.jsp the id first name email last name etc will be entered in one page reg.jsp. the problem column will be entered on the contact.jsp page. how do you do this? check my code below
to start, i have created a database:
CREATE TABLE `members` ( `id` int(10) unsigned NOT NULL auto_increment, `first_name` varchar(45) NOT NULL, `last_name` varchar(45) NOT NULL, `email` varchar(45) NOT NULL, `uname` varchar(45) NOT NULL, `pass` varchar(45) NOT NULL, `regdate` date NOT NULL, problem char(250) NOT NULL PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
the id,first name, last name, email, uname, pass, regdate can be inserted here:
reg.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>REGISTRATION</title> </head> <body bgcolor="#BDBDBD"> <form method="post" action="registration.jsp"> <center> <table border="1" width="30%" cellpadding="5"> <thead> <tr> <th colspan="2">Enter Information Here</th> </tr> </thead> <tbody> <tr> <td>First Name</td> <td><input type="text" name="fname" value="" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lname" value="" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="" /></td> </tr> <tr> <td>User Name</td> <td><input type="text" name="uname" value="" /></td> </tr> <tr> <td>Password</td> <td><input type="password" name="pass" value="" /></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> <td><input type="reset" value="Reset" /></td> </tr> <tr> <td colspan="2">Already registered!! <a href="index.jsp">Login Here</a></td> </tr> </tbody> </table> </center> </form> </body> </html>
registration.jsp
<%@ page import ="java.sql.*" %> <% String user = request.getParameter("uname"); String pwd = request.getParameter("pass"); String fname = request.getParameter("fname"); String lname = request.getParameter("lname"); String email = request.getParameter("email"); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "root", ""); Statement st = con.createStatement(); ResultSet rs; int i = st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE())"); if (i > 0) { //session.setAttribute("userid", user); response.sendRedirect("welcome.jsp"); // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>"); } else { response.sendRedirect("index.jsp"); } %>
and my problem column can be enter here:
contact.jsp
<title>CONTACT US</title> <body bgcolor="#BDBDBD"> <table border=1 align="center"<tr><td> <% if ((session.getAttribute("userid") == null) || (session.getAttribute("userid") == "")) { %> You are not logged in<br/> <a href="index.jsp">Please Login</a> <%} else { %> <form method="post" action="problem.jsp"> <%=session.getAttribute("userid")%><br /> </tr></td><tr><td> Have a question for us?</tr></td><tr><td> Enter your question here(250):</tr></td><tr><td> <textarea rows="4" cols="50"></textarea></tr></td> <tr><td>EMAIL <input type="text" name="email" id="email" /> </tr></td> <tr><td> <input type="submit" value="Login" /> </tr></td> </table> </form> <% } %> </body>
and in here. here is my problem i dont really know how to do this. i want to enter a question and the question i enter will be saved to the problem column. here is my code:
problem.jsp
<%@page import="java.sql.*"%> <%@page import="java.io.*"%> <% String prob = request.getParameter("problem"); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "root", ""); Statement st = con.createStatement(); ResultSet rs; int i = st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate, problem) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE(),'" + prob +"'"); if (i > 0) { //session.setAttribute("userid", user); response.sendRedirect("welcome.jsp"); // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>"); } else { response.sendRedirect("index.jsp"); } %>