minhas4all
09-14-2005, 06:34 AM
hello to all
i just want to update table data using form and then on submitting it goes to update page for changing and again on submitting it should update that field but it didn't
and giving the error message
Incorrect syntax near the keyword 'WHERE'
here is my form code
<html>
<body>
<%
Set Conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = medicalrecords; User Id = sa; Password="
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM users1",conn
%>
<h2>List Update</h2>
<table border="1" width="39%">
<tr> <%
for each x in rs.Fields
response.write("<th>" & ucase(x.name) & "</th>")
next %>
</tr>
<% do until rs.EOF %>
<tr>
<form method="post" action="update.asp">
<%
for each x in rs.Fields
if lcase(x.name)="uname" then%>
<td>
<input type="submit" name="uname" value="<%=x.value%>" >
</td>
<% else %>
<td><%Response.Write(x.value)%></td>
<%end if
next %>
</form>
<%rs.MoveNext%>
</tr> <%
loop %>
</table>
</body>
</html>
and when i clink any of name in name field it goes to update page showing the all details now i have to make any changes and submit and it shows the error
here is my other code
<html>
<body><h2>Update Record</h2>
<%
Dim cname
Set Conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = medicalrecords; User Id = sa; Password="
cname=Request.Form("uname")
if Request.form("pword")="" then
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM users1 WHERE uname='" & cname & "'",conn
%>
<form method="post" action="update.asp">
<table>
<%for each x in rs.Fields%>
<tr><td><%=x.name%></td>
<td><%
if lcase(x.name)="pword" then %>
<td><input type="password" name="<%=x.name%>" value="<%=x.value%>"></td>
<% else %>
<td><input name="<%=x.name%>" value="<%=x.value%>"></td>
<%end if %>
<%next%>
</tr>
</table>
<br /><br />
<input type="submit" value="Update record">
</form>
<%
else
sql="UPDATE users1 SET "
sql=sql & "uname='" & Request.Form("uname") & "',"
sql=sql & "pword='" & Request.Form("pword") & "',"
sql=sql & "phint='" & Request.Form("phint") & "',"
sql=sql & " WHERE uname='" & cname & "'"
on error resume next
conn.Execute sql
if err<>0 then
response.write err.description
else
response.write("Record " & cname & " was updated!")
end if
end if
conn.close
%>
</body>
</html>
so please you all tell me that where is problem in my code
i m not sure that i explain my problem well or not
thanks in advance
i just want to update table data using form and then on submitting it goes to update page for changing and again on submitting it should update that field but it didn't
and giving the error message
Incorrect syntax near the keyword 'WHERE'
here is my form code
<html>
<body>
<%
Set Conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = medicalrecords; User Id = sa; Password="
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM users1",conn
%>
<h2>List Update</h2>
<table border="1" width="39%">
<tr> <%
for each x in rs.Fields
response.write("<th>" & ucase(x.name) & "</th>")
next %>
</tr>
<% do until rs.EOF %>
<tr>
<form method="post" action="update.asp">
<%
for each x in rs.Fields
if lcase(x.name)="uname" then%>
<td>
<input type="submit" name="uname" value="<%=x.value%>" >
</td>
<% else %>
<td><%Response.Write(x.value)%></td>
<%end if
next %>
</form>
<%rs.MoveNext%>
</tr> <%
loop %>
</table>
</body>
</html>
and when i clink any of name in name field it goes to update page showing the all details now i have to make any changes and submit and it shows the error
here is my other code
<html>
<body><h2>Update Record</h2>
<%
Dim cname
Set Conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = medicalrecords; User Id = sa; Password="
cname=Request.Form("uname")
if Request.form("pword")="" then
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM users1 WHERE uname='" & cname & "'",conn
%>
<form method="post" action="update.asp">
<table>
<%for each x in rs.Fields%>
<tr><td><%=x.name%></td>
<td><%
if lcase(x.name)="pword" then %>
<td><input type="password" name="<%=x.name%>" value="<%=x.value%>"></td>
<% else %>
<td><input name="<%=x.name%>" value="<%=x.value%>"></td>
<%end if %>
<%next%>
</tr>
</table>
<br /><br />
<input type="submit" value="Update record">
</form>
<%
else
sql="UPDATE users1 SET "
sql=sql & "uname='" & Request.Form("uname") & "',"
sql=sql & "pword='" & Request.Form("pword") & "',"
sql=sql & "phint='" & Request.Form("phint") & "',"
sql=sql & " WHERE uname='" & cname & "'"
on error resume next
conn.Execute sql
if err<>0 then
response.write err.description
else
response.write("Record " & cname & " was updated!")
end if
end if
conn.close
%>
</body>
</html>
so please you all tell me that where is problem in my code
i m not sure that i explain my problem well or not
thanks in advance