Hey guys,
I'm setting up a new page to connect to a recordset and only update a record that exists. The page is supposed to compare three fields in the record (to know which record to update). I know the page is working, it returns the error "No update permissions!". I still don't know if the code is right. I think I've removed any mis-spellings. Here is the entire page:
Any suggestions?
I'm setting up a new page to connect to a recordset and only update a record that exists. The page is supposed to compare three fields in the record (to know which record to update). I know the page is working, it returns the error "No update permissions!". I still don't know if the code is right. I think I've removed any mis-spellings. Here is the entire page:
Code:
<%
[COLOR=green]'connect to DB[/color]
Dim conn
Dim connectstr
Dim db_name, db_usrname, db_usrpwd
Dim db_table
Dim db_server
Dim fnUpdStr, lnUpdStr, ad1UpdStr
db_server= "[COLOR=green][i]SERVER_NAME[/i][/color]"
db_name= "[COLOR=green][i]DATABASE_NAME[/i][/color]"
db_table= "[COLOR=green][i]TABLE_NAME[/i][/color]"
db_usrname= "[COLOR=green][i]USER_NAME[/i][/color]"
db_usrpwd= "[COLOR=green][i]PASSWORD[/i][/color]"
%>
<h3>Update Record</h3>
<%
[COLOR=green]'connect to DB.Recordset[/color]
set conn=Server.CreateObject("ADODB.Connection")
connectstr= "Driver={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_usrname & ";PWD=" & db_usrpwd
conn.Open connectstr
fnUpdStr= Request.Form("fname")
lnUpdStr= Request.Form("lname")
ad1UpdStr= Request.Form("address1")
if Request.form("fname")="" then
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM customers WHERE fname='" & fnUpdStr & "' AND lname='" & lnUpdStr & "' AND address1='" & ad1UpdStr & "'",conn
%>
[COLOR=green]'display the form[/color]
<form method="post" action="[COLOR=green][i]SAME_ASP_PAGE[/i][/color]">
<table>
<%for each x in rs.Fields%>
<tr>
<td><%=x.name%></td>
<td><input name="<%=x.name%>" value="<%=x.value%>" size="20"></td>
<%next%>
</tr>
</table>
<br /><br />
<input type="submit" value="Update record">
</form>
[COLOR=green]'establish update argument[/color]
<%
else
sql="UPDATE customers SET "
sql=sql & "fname='" & Request.Form("fname") & "',"
sql=sql & "lname='" & Request.Form("lname") & "',"
sql=sql & "address1='" & Request.Form("address1") & "',"
sql=sql & "address2='" & Request.Form("address2") & "',"
sql=sql & "city='" & Request.Form("city") & "',"
sql=sql & "state='" & Request.Form("state") & "',"
sql=sql & "zip='" & Request.Form("zip") & "',"
sql=sql & "country='" & Request.Form("country") & "'"
sql=sql & "homephone='" & Request.Form("homephone") & "',"
sql=sql & "cellphone='" & Request.Form("cellphone") & "',"
sql=sql & "email='" & Request.Form("email") & "',"
sql=sql & " WHERE fname='" & fnUpdStr & "' AND lname='" & lnUpdStr & "' AND address1='" & ad1UpdStr & "'"
on error resume next
conn.Execute sql
if err<>0 then
response.write("No update permissions!")
else
response.write("Record " & cid & " was updated!")
end if
end if
conn.close
%>
Any suggestions?