2012-11-01 49 views
0

我一直在使用Google搜索幾個小時,但仍然無法理解這一點!將表單數據添加到數據庫ASP和SQL服務器

首先,我有這個代碼,這是我創建的形式。

<!-- #include file="Header.asp" --> 
<!-- #include file="Tauthenticate.asp" --> 
<!--#include file="database.asp"--> 

<SCRIPT LANGUAGE="JavaScript"> 

function confirmSubmit() 
{ 
var agree=confirm("Confirm?"); 
if (agree) 
return true ; 
else 
return false ; 
} 
</script> 


    <table border="0" width="100%" cellspacing="0" cellpadding="0" id="table17"> 
     <tr> 
      <td background="../images/bar1.jpg"><font size="2">&nbsp;<b>Add 
      Skill</b></font></td> 
     </tr> 
     </table> 
      <table border="0" width="100%" id="table18" cellspacing="0" cellpadding="0"> 
       <form method="POST" action="SaveNewSkill.asp"> 
       <tr> 

       </tr> 

       <td width="108"><font face="Verdana" size="2" >Employee </font> </td> 
    <td> 


     <p><font face="Verdana"><select size="1" name="D1"> 
     <% 
      sql="select User_ID, First_Name, Surname from Company Where Status not like 'left%' and (Company.Office='Manchester' or Company.Office='Romania') order by Surname" 
      set users=conn.execute(sql) 
      do while not users.eof 
       %> 
        <option value="<%=users("User_ID")%>"><%=users("First_Name") & " " & users("Surname")%></option> 
       <% 
       users.movenext 
       loop 
       set users=nothing 
       %> 
     </select></font></p> 

    </td> 


       <tr> 
        <td width="142"><b><font size="2" face="Verdana">Skill</font></b></td><td> 
        <select size="1" name="D3"> 
        <option value="AutoCad 2D">AutoCAD 2D</option> 
        <option value="3D Modeling">3D Modeling</option> 
        <option value="Sketchup">Sketchup</option> 
        </select></td> 

       </tr> 

       <tr> 
        <td width="142"><b><font size="2" face="Verdana">Current Skill Level</font></b></td><td> 
        <select size="1" name="D4"> 
        <option value="1">1</option> 
        <option value="2">2</option> 
        <option value="3">3</option> 
        <option value="4">4</option> 
        <option value="5">5</option> 
        </select></td> 

       </tr> 

        <tr> 
        <td width="142"><b><font size="2" face="Verdana">Required Skill Level</font></b></td><td> 
        <select size="1" name="D4"> 
        <option value="1">1</option> 
        <option value="2">2</option> 
        <option value="3">3</option> 
        <option value="4">4</option> 
        <option value="5">5</option> 
        </select></td> 

       </tr> 

       </form> 
       </table> 
    <form><p><font size="2"><input type="submit" value="Save" name="B1" onclick="return confirmSubmit()"></font></form> 
    <td width="75"> 
      <!-- #include file="footer.asp" --> 

包含的文件用於標題,數據庫連接和身份驗證以便首先查看頁面(這都適用)。

表單爲我們的用戶列表查詢數據庫,然後允許用戶從列表中選擇技能並定義他們當前的專業水平。

我已經創建了這個「保存技能」的asp頁面。

<!--#include file="database.asp"--> 
<!--#include File="TUauthenticate.asp"--> 


<% 


User_ID=request.querystring("User_ID") 
sql="select * from company where User_ID=" & User_ID 
set rs=conn.execute(sql) 
Session("User_ID")=User_ID 


Skill=request.form("D3") 
Current_Level=Request.form("D4") 
User_ID=request.form("D1") 
Required_Level=request.form("D5") 

if request.form("B1")<>"" then 
if skill = "AutoCAD 2D" then 
sqlq="insert into skills (User_ID, AutoCad_2D, AutoCad_2DR) Values (" & User_ID & ",'" & Current_Level & "','" & Required_Level & "')" 
response.write(sqlq) 
set rs=conn.execute(sqlq) 
end if 
end if 

%> 

我已經把這個一起使用各條工作代碼,但它不會保存到數據庫中...我明白它不是很整齊,但我會排序,一旦我知道什麼是錯。

我知道我已經包含的JavaScript的一點點,但如果答案是ASP代碼中我會prefare(作爲即時通訊目前正在努力學習ASP)提前傢伙

謝謝! :d

+0

這是什麼結果。一個錯誤或一個空值 – polin

+0

你的response.write(sqlq)寫入網頁是什麼? –

+0

它實際上並沒有做任何事情哈哈,只是重置表單中的所有值,就好像它重定向到那裏但實際上沒有添加到數據庫中...... –

回答

1

你的代碼看,你只能看到你的Response.Write(sqlq)如果滿足以下條件的響應:

1)如果B1 =沒有

2)他們選擇從選擇框中選擇AutoCAD 2D。

所以這裏有兩個潛在的問題。

我建議刪除if request.form(「B1」)<>「」然後需求並再次嘗試,確保您選擇AutoCAD 2D選項。

0
<% 


sdate =request.form("T1") 
stime =request.form("T2") 
datetime=sdate & " " & stime 

iUserID=request.form("D2") 
iSkillLevel=request.form("D4") 
iRSkillLevel=request.form("D5") 
hdid=Session("hdid") 
wuser=Request.ServerVariables("Logon_User") 

uploadid=request.form("D56") 
filepath=request.form("B23") 
hyperlink=request.form("T6") 


If Request.Form("B11") <> "" then 
sqlq = "INSERT INTO Skills (User_ID, AutoCad_2D, AutoCad_2DR) VALUES ('" & iUserID & "','" & iSkillLevel & "','" & iRSkillLevel & "')" 
response.write(sqlq) 
set rs=conn.execute(sqlq) 
end if 

set rs=nothing 
If Request.Form("B11") <> "" Then Response.Redirect(Session("lastpage")) 

%> 
+0

感謝您的幫助傢伙!我真的結束了重新寫它,我認爲也有一個衝突的變量(User_ID)。所有它的作品,我只需要包括多個if語句,以便用戶可以從列表中選擇不同的技能:) –

相關問題