Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

How to update data using webpage submit button? (no replies)

$
0
0
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"&gt;

<%
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?

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>