How to update data using webpage submit button?
Posted by: mat bar
Date: March 17, 2014 01:51PM

Hello
My question is how to update data using webpage submit button?



In theory , i need to get parameter from field 1("getint") and after button Dispense[2] is clicked database data[3] is decremented by value from field 1. So for example if drug number 3 shows us quantity 21 and user wants dispense 4 boxes of aranesp drug field gonna be updated and 4 boxes are going to be decremented.

This is my code



<%@ page language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    	               "http://www.w3.org/TR/html4/loose.dtd">;

<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database","root", "asdqwe");
%>


<html>
<head>
<title>Successfully Login by JSP</title>
<link rel="stylesheet" type="text/css" href="resources/css/maincss.css">
<link rel="stylesheet" type="text/css" href="resources/css/style_table.css">
</head>
<script type="text/javascript">

function menuLogOut()
{	
document.location.href("logOut.jsp"); 
}	


</script>

<body>
<div id="loggedas_stock_check">
<img src=img/logged_as.png border="0">
	<div id=loggedas_nick_stock_check>
	<%
	out.print(session.getAttribute("suserid")+ "</b>"+"<br>");
	%>
	</div>
</div>

<div id="wyloguj_stock_check">
<a href="" onclick="javascript:menuLogOut();"><img src=img/logout.png border="0"></a>
</div>

<br>


<form method="post">

<table class="bordered">
    <thead>

    <tr>
        <th>No</th>        
        <th>Drug Name</th>
        <th>Strength</th>
        <th>Quantity</th>
        <th>Dis Qty</th>            
    </tr>
    </thead>
     <%
try
{

String query="select * from drugs";

Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{

%>
   <tr> 
   <td><%=rs.getInt("drugid") %></td> 
   <td><%=rs.getString("drugname") %></td> 
   <td><%=rs.getString("strength") %></td>
   <td><%=rs.getInt("drugquant") %></td>
   <td><INPUT TYPE="TEXT" NAME="getint" SIZE="7">
       <INPUT TYPE="SUBMIT" VALUE="Dispense" NAME="B1"></td>
   </tr>
      
        <%
      
}
%>
</table>
    <%
    rs.close();
    stmt.close();
    conn.close();
    }
catch(Exception e)
{
    e.printStackTrace();
    }

%>

</form>
</body>
</html>

Could anyone help me please?

Options: ReplyQuote


Subject
Written By
Posted
How to update data using webpage submit button?
March 17, 2014 01:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.