大家好:
我用JSP做了一個SQL 更改的網頁,如下圖
我先勾選要改的資料,按選擇後,他就會出現我要改的格子
我的問題是,出現更改畫面,我改數字,按更新後,但都沒反應,不知哪裡有誤,請各位大大幫忙,
謝謝
以下附程式碼:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file = "db.jsp"%> //db connect
<!DOCTYPE html>
<html>
<body>
<%
int i;
String[] a =request.getParameterValues("a");
String name2 = request.getParameter("name");
//////就是這段都沒反應//////////
if( a!=null && request.getParameter("fix") != null ){
out.println(name2);//
for(i=0;i<a.length;i++){
String num = a[i];
out.println(name2);
String sql = "update send set name = '" + name2 + "' where c_id ='" + a[i] + "' ";
int b = stmt.executeUpdate(sql);
}
}
//////////////////////////////////
%>
<form action = "update.jsp" method = "post">
<% if(request.getParameter("update") != null && a!=null)
{ for(i=0;i<a.length;i++){
String sql="select * from send where c_id = '" + a[i] + "' ";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
%>
<%=a[i]%>
客戶名稱 : <input type = "text" name= "name" size = "15" value = "<%=rs.getString("name")%>"> <br>
<% } }}%>
<input type = "submit" name = "fix" value = "更新">
</form>
<form action = "update.jsp" method = "post">
<table border="1"><tr><th>選項</th><th>客戶代號</th><th>客戶名稱</th></tr>
<%
String sql = "select * from send";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
String name = rs.getString("name");
String c_id = rs.getString("c_id");
out.print("<tr><td>"+"<input type=checkbox name='a' value="+c_id+">"+"</td><td>"+ c_id + "</td><td>"+name+"</td></tr> ");
}
rs.close();
%>
</table> </br>
<input type = "submit" name = "update" value = "選擇">
</form>
</body>
</html>
</html>
先確定a 和 name2有沒有收到值,值是什麼樣的?
String[] a =request.getParameterValues("a");
String name2 = request.getParameter("name");
多值
https://gist.github.com/PrabhjotSingh/4189307
String Values[] = request.getParameterValues("name");