iT邦幫忙

0

JSP傳值SQL更改沒反應

大家好:
我用JSP做了一個SQL 更改的網頁,如下圖
我先勾選要改的資料,按選擇後,他就會出現我要改的格子

我的問題是,出現更改畫面,我改數字,按更新後,但都沒反應,不知哪裡有誤,請各位大大幫忙,
謝謝
https://ithelp.ithome.com.tw/upload/images/20180926/201029837Txuv8JbkF.png

以下附程式碼:

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

    
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
最佳解答

先確定a 和 name2有沒有收到值,值是什麼樣的?

String[] a =request.getParameterValues("a"); 
String name2 = request.getParameter("name");

多值
https://gist.github.com/PrabhjotSingh/4189307

String Values[] = request.getParameterValues("name"); 
看更多先前的回應...收起先前的回應...
神威 iT邦研究生 4 級 ‧ 2018-09-26 16:59:03 檢舉

https://ithelp.ithome.com.tw/upload/images/20180926/20102983kkQBObkoRb.png
都有抓到正常值

Homura iT邦高手 1 級 ‧ 2018-09-26 19:41:45 檢舉

有傳回去看看資料庫有沒有寫進去@@

神威 iT邦研究生 4 級 ‧ 2018-09-27 08:07:59 檢舉

大大好:
我的參數有傳到了
但是我發現只能傳一筆
第二筆他就改不到了....
不知為什麼
請大大幫忙解惑,謝謝

多值請參考上面…

把SQL印出來看看~有沒有問題~
out.println(sql);

神威 iT邦研究生 4 級 ‧ 2018-09-27 10:31:00 檢舉

跟著鄉民看熱鬧
可以了,謝謝
Homura
純真的人
也謝謝你們的回應

我要發表回答

立即登入回答