SQL UPDATE sætning
Hej.Jeg har lavet en update sætning som lige inden den updater, tjecker databasen og ser om brugernavnet er taget. Jeg har bare det problem, at hvis jeg ikke ændrer i brugernavnet, så siger den at det stadig er optaget... Hvordan kan jeg fjerne det..? har prøvet noget med if rs("id")=strID men kan slet ikke finde rundt i det...
<!--#include virtual="/_inc/dbconn.asp"-->
<!--#include virtual="/_inc/userpage_protect.asp"-->
<h1>Rediger min profil</h1>
<%
openConn()
strCmd = Request.Querystring("cmd")
If strCmd = "update" Then
strID = Request.Form("id")
strUsername = Replace(Request.Form("username"),"'","´")
strPassword = Replace(Request.Form("password"),"'","´")
strName = Replace(Request.Form("name"),"'","´")
strAge = Replace(Request.Form("age"),"'","´")
strAdress = Replace(Request.Form("adress"),"'","´")
strZip = Replace(Request.Form("zip"),"'","´")
strCity = Replace(Request.Form("city"),"'","´")
strPhone = Replace(Request.Form("phone"),"'","´")
strMobile = Replace(Request.Form("mobile"),"'","´")
strEmail = Replace(Request.Form("email"),"'","´")
strHomepage = Replace(Request.Form("homepage"),"'","´")
strMessenger = Replace(Request.Form("messenger"),"'","´")
strContext = Replace(Request.Form("context"),"'","´")
strContext = Replace(strContext,"vbCrLf","<br>")
strSQL = "SELECT user.id,user.username FROM user WHERE user.username='" & strUsername & "'"
Set rs = connection.Execute(strSQL)
If (rs.EOF or rs.BOF) Then
strSQL2 = "UPDATE user SET username='" & strUsername & "',password='" & strPassword & "' WHERE user.id=" & strID
Set rs2 = connection.Execute(strSQL2)
strSQL1 = "UPDATE user_profile SET [name]='" & strName & "',[age]='" & strAge & "',[adress]='" & strAdress & "',[zip]='" & strZip & "',[city]='" & strCity & "',[phone]='" & strPhone & "',[mobile]='" & strMobile & "',[email]='" & strEmail & "',[homepage]='" & strHomepage & "',[messenger]='" & strMessenger & "',[context]='" & strContext & "' WHERE user_profile.userid=" & strID
Set rs1 = connection.Execute(strSQL1)
'Response.Write(strSQL)
Response.Redirect("/?pID=400")
Else
Response.Write("Brugernavnet er optaget! Vælg et andet")
End if
Else
strID = Session("userid")
If strID = "" Then
Response.Write("Der er sket en fejl! Prøv og log ind igen.")
Else
strSQL = "SELECT user.username,user.password,user.type,user_type.id,user_type.type as usertype,user_profile.name,user_profile.age,user_profile.adress,user_profile.zip,user_profile.city,user_profile.phone,user_profile.mobile,user_profile.email,user_profile.homepage,user_profile.messenger,user_profile.context FROM user,user_type,user_profile WHERE user.id=" & strID & " AND user.type=user_type.id AND user_profile.id=user.id"
set rs = connection.Execute(strSQL)
If Not (rs.EOF or rs.BOF) Then
%>
<form method="post" action="/default.asp?pID=401&cmd=update" name="update">
<table border="0" cellpadding="0" cellspacing="0" style="width:300px;">
<tr>
<td style="width:100px;"><b>Brugernavn:</b></td>
<td style="width:200px;height:20px;"><input type="text" name="username" value="<%=rs("username")%>" class="input"></td>
</tr>
<tr>
<td><b>Adgangskode:</b></td>
<td style="height:20px;"><input type="text" name="password" value="<%=rs("password")%>" class="input"></td>
</tr>
<tr>
<td><b>Brugertype:</b></td>
<td style="height:20px;"><%=rs("usertype")%></td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td><b>Navn:</b></td>
<td style="height:20px;"><input type="text" name="name" value="<%=rs("name")%>" class="input"></td>
</tr>
<tr>
<td><b>Alder:</b></td>
<td style="height:20px;"><input type="text" name="age" value="<%=rs("age")%>" class="input"></td>
</tr>
<tr>
<td><b>Adresse:</b></td>
<td style="height:20px;"><input type="text" name="adress" value="<%=rs("adress")%>" class="input"></td>
</tr>
<tr>
<td><b>Postnr. & by:</b></td>
<td style="height:20px;"><input type="text" name="zip" value="<%=rs("zip")%>" style="width:40px;" class="input"> <input type="text" name="city" value="<%=rs("city")%>" style="width:92px;" class="input"></td>
</tr>
<tr>
<td><b>Telefon:</b></td>
<td style="height:20px;"><input type="text" name="phone" value="<%=rs("phone")%>" class="input"></td>
</tr>
<tr>
<td><b>Mobil:</b></td>
<td style="height:20px;"><input type="text" name="mobile" value="<%=rs("mobile")%>" class="input"></td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="5" cellspacing="0" style="width:100%;" class="input">
<tr>
<td style="width:30px;text-align:center;"><img src="/gfx/mail.gif" alt="<%If IsNull(rs("email"))=True Then%><%Else%>E-mailadresse: <%=rs("email")%><%End if%>" width="13" height="11" border="0"></td>
<td style="padding-left:5px;height:20px;"><input type="text" name="email" value="<%=rs("email")%>" class="input" style="background-color:#ffffff;"></td>
</tr>
<tr>
<td style="width:30px;text-align:center;"><img src="/gfx/www.gif" alt="<%If IsNull(rs("homepage"))=True Then%><%Else%>Hjemmeside: <%=rs("homepage")%><%End if%>" width="16" height="16" border="0"></td>
<td style="padding-left:5px;height:20px;"><input type="text" name="homepage" value="<%=rs("homepage")%>" class="input" style="background-color:#ffffff;"></td>
</tr>
<tr>
<td style="width:30px;text-align:center;"><img src="/gfx/messenger.gif" alt="<%If IsNull(rs("messenger"))=True Then%><%Else%>Messengeradresse: <%=rs("messenger")%><%End if%>" width="16" height="16" border="0"></td>
<td style="padding-left:5px;height:20px;"><input type="text" name="messenger" value="<%=rs("messenger")%>" class="input" style="background-color:#ffffff;"></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td colspan="2"><b>Profiltekst:</b></td>
</tr>
<tr><td colspan="2">
<textarea style="width:100%;height:53px;" name="context"><%=rs("context")%></textarea><input type="hidden" name="id" value="<%=rs("id")%>"></td></tr>
</table>
<br>
<hr class="point">
<div align="right"><a href="java script:document.update.submit();" class="navigate">gem profil</a> - <a href="#" class="navigate">slet profil</a></div>
</form>
<%
End if
closeConn()
End if
End if
%>
