Share on Google+Share on Google+

srilatha
qurey
2 Answer(s)      6 years and 11 months ago
Posted in : SQL
hello sir
i have 2 tables,one is user_details and the other is employee.
in user_details i have given a userid varchar(10) primary key,username varchar(20),password varchar(10).This is login process of my proj.And in employee table also i have to give userid,username,password.This is sign up process. when i enter this id,name and password in employee it should automatically store in user_details also.how should i write the query.plz tell me.

thank u

Ads

View Answers

May 19, 2010 at 11:37 AM


Hi Friend,

Try the following code:

1)login.jsp:

<html>
<head>
<style>
A:hover {
text-decoration: none;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
A {
text-decoration: underline;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
</style>
</head>
<body>
<br><br><br>
<form name="loginform" method="post" action="loginmid.jsp" >
<table width="250px" border=0 align="center" style="background-color:ffeeff;">
<tr>
<td colspan=2 align="center" style="font-weight:bold;font-size:20pt;" align="center">User Login</td>
</tr>
<tr>
<td colspan=2>&nbsp;</td>
</tr>
<tr>
<td style="font-size:12pt;" align="center">Login Name</td>
<td><input type="text" name="userName" value=""></td>
</tr>
<tr>
<td style="font-size:12pt;" align="center">Password</td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
<tr>
<td></td>
<td align="right"><a href="register.jsp">New User?</a></td>
</tr>
</table>
</form>
</body>
</html>

2)loginmid.jsp:

<%@ page language="java" import="java.sql.*;"%>
<html>
<body>
<%
String userName = request.getParameter("userName");
String password = request.getParameter("password");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st = conn.createStatement();
String strQuery = "select count(*) from user_details where username='"+userName+"' and password='"+password+"'";
ResultSet rs = st.executeQuery(strQuery);
if(rs.next()){
if(rs.getInt(1)>0){
out.println("Welcome "+userName);
}
else{
response.sendRedirect("login.jsp");
}
}
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>


May 19, 2010 at 11:38 AM


continue..

3)register.jsp:

<%@ page import="java.sql.*"%>
<html>
<body>
<br>
<form name="userform" method="post" >
<table width="350px" border=0 align="center" style="background-color:ffeeff;">
<tr><td colspan=2 style="font-weight:bold;font-size:20pt;" align="center">User Registeration</td>
</tr><tr><td colspan=2>&nbsp;</td>
</tr><tr><td>First Name </td>
<td><input type="text" name="firstName" ></td>
</tr><tr><td>Last Name </td>
<td><input type="text" name="lastname"></td>
</tr><tr>
<td>Login Name</td>
<td><input type="text" name="userName" ></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" ></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" ></td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows=5 cols=25></textarea></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contactNo" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Save"></td>
</tr>
</table>
</form>
</body>
</html>
<%
String fname=request.getParameter("firstName");
String lname=request.getParameter("lastName");
String uname=request.getParameter("userName");
String password=request.getParameter("password");
String email=request.getParameter("email");
String address=request.getParameter("address");
String contact=request.getParameter("contactNo");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st = conn.createStatement();
int i=st.executeUpdate("insert into employee(firstname,lastname,username,password,email,address,contactNo) values('"+fname+"','"+lname+"','"+uname+"','"+password+"','"+email+"','"+address+"','"+contact+"')");
int j=st.executeUpdate("insert into user_details(username,password) values('"+uname+"','"+password+"')");
}
catch(Exception e){}
%>

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
Advertisements
array
array  How to store the results of mysql query in an array and display the result in web page.? for exemple I need to store the result of following qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select
Sql Querie
39 3 old 41 49 write a qurey to get
myfaces,hibernate and spring integration - Hibernate
myfaces,hibernate and spring integration  sorry, in the previous qurey i have mentioned the Wrong URL.the right url is: http://www.roseindia.net/jsf/myfacesspring/downloadcode.shtml the code given in this url : http
Tutorials   
Java Spring Hibernate Struts Training How to Fetch Data using dropdown option How to get day from date in SQL? Example of sorting results in MySQL Distinct and Limit example in MySQL How to download install and use MySQL workbench? Example of Average, Sum, Min and Max functions in MySQL How to delete data from MySQL? Update SQL Query Example Order by example in MySQL AND and OR Operators in MySQL Query Where clause with query in MySQL How to use select Statement in MySQL? How to insert data into MySQL Table? Create Database and tables in MySQL example of before insert trigger in mysql Failed to Call Procedure MY Sql Query Error - Not able to Understand the issue which query will be run for previous(button) question How to access data yearly from DB in C# ? Fastest way to upload huge raw data in database - c#, Java or stored procedure DB Insert Nb hours between 2 time stamps meets specific criteria mysql select into table from another table example MySQLselect into new table Example code How to create a .mdf file from script (.sql) Please help me out fixing broken relational links in MySQL database after an upgrade How do I upgrade mysql? mysql 4.x to 5.x upgrade problem Upgrading a PHP/MYSQL application? upgrading sql query join phpmyadmin in whm whm php version update php cpanel cpanel mysql downgrade cpanel mysql version upgrade mysql whm upgrade mysql 4 5 cpanel upgrade mysql cpanel server Did my upgrade from mySQL 5.1 to 5.5 work Upgrade to MySQL 5.5 ? - cPanel Mem use upgrade from MySQL 5.1 to 5.5 - cPanel Upgrading MySQL from 5.0 to 5.1 or 5.5 - cPanel Mysql Upgrade on WHM (Mysql 5.1 to 5.5)cPanel Mysql Upgrade on WHM (Mysql 5.1 to 5.5) - cPanel Updating from MySQL 5.0 to 5.5 cPanel MySQL 5.1 upgrade to 5.5 error Charset problem upon publishing PHP + MySQL website MySQL issue: Table 'data_dictionary.CHARACTER_SETS' doesn't exist SQL Error Version 5.5.15

Ads

 
Advertisement null

Ads