i have connected my login.jsp and registration.jsp to my database, signup is successful but when i login i get error message "password invalid" i think my code has a problem, please can someone help me solve that, the code is found below . Thanks in advance.
login.jsp
<%@ page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String email = request.getParameter("emailsignup");
String password = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mldn","root","shaddy");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from members WHERE uname='" + userid + "' and password='" + password +"'");
if (rs.next()) {
session.setAttribute("userid", userid);
out.println("welcome " + userid);
out.println("<a href='logout.jsp'>Log out</a>");
response.sendRedirect("<a href='index.jsp'>Welcome</a>");
} else {
out.println("Invalid password <a href='index.jsp'>try again</a>");
}
%>
HTML
<header>
<h1>Geo Business/Land inventory<br><span>Login And Registration</span></h1>
</header>
<section>
<div id="container_demo" >
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form action = 'jsp/login.jsp'>
<h1>Log in</h1>
<p>
<label for="username" class="uname" data-icon="u" > Your Username </label>
<input id="username" name="username" required="required" type="text" placeholder="myusername." value=""/>
</p>
<p>
<label for="password" class="youpasswd" data-icon="p"> Your password </label>
<input id="password" name="password" required="required" type="password" placeholder=" X8df!90EO" value=""/>
</p>
<p class="keeplogin">
<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
<label for="loginkeeping">Keep me logged in</label>
</p>
<p class="login button">
<input type="submit" value="Login" />
</p>
<p class="change_link">
Not a member yet ?
<a href="#toregister" class="to_register">Join us</a>
</p>
</form>
</div>
<div id="register" class="animate form">
<form action = 'jsp/registration.jsp'>
<h1> Sign up </h1>
<p>
<label for="fname" class="fname" data-icon="fn">First Name</label>
<input id="fname" name="fname" required="required" type="text" placeholder="myfirstname" value=""/>
</p>
<p>
<label for="lname" class="lname" data-icon="ln" >Last Name</label>
<input id="lname" name="lname" required="required" type="text" placeholder="lastname" value=""/>
</p>
<p>
<label for="email" class="emailsignup" data-icon="e" >Email</label>
<input id="email" name="email" required="required" type="email" placeholder="[email protected]" value=""/>
</p
<p>
<label for="username" class="uname" data-icon="u">Username </label>
<input id="username" name="username" required="required" type="username" placeholder="eg. X8df!90EO" value=""/>
</p>
<p>
<label for="password" class="youpasswd" data-icon="p">Password </label>
<input id="password" name="password" required="required" type="password" placeholder=" eg.X8df!90EO" value="" />
</p>
<p class="signin button">
<input type="submit" value="Sign up"/>
</p>
<p class="change_link">
Already a member ?
<a href="#tologin" class="to_register"> Go and log in </a>
</p>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
</html>
PreparedStatementistead ofStatement, also whats the column type of password in table? Here spaces might be an issue.