Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regarding Update statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am ASP newbie. I have few fields that requires me to update. But i am not sure how to combine all this fields to make it into one UPDATE statement. By the way, how to update records in 2 different tables in 1 database.

Thank You? :cool:
 
You can use Request.Form ("field_name") to get the form data from previous page or same page, then construct your update statetment like this:

sql = "UPDATE tablename SET comething = '"&Request.Form ("field_name")&"'" ------------------
Freedom is a Right
 
Is my following code correct?
myName=request("text1") means that i am getting the data from the textbox.



<%

Dim DataConn ' ADO connection object
Dim sql_update, ConnString, objRs
Dim myName, myUserID, myPwd, myDept, myYr, myEmail, SQL

myName = request(&quot;text1&quot;)
myUserID = request(&quot;text2&quot;)
myPwd = request(&quot;password1&quot;)
myDept = request(&quot;select1&quot;)
myYr = request(&quot;radio1&quot;)
myEmail= request(&quot;text3&quot;)

Set DataConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
ConnString=&quot;driver={sql server};server=CON7; database=user;DSN=localserver;PWD=sa;UID=sa;&quot;
DataConn.open ConnString

Set objRs=server.CreateObject (&quot;ADODB.Recordset&quot;)


SQL = &quot;UPDATE info&quot;
SQL = SQL & &quot; SET NameID='&quot; & myName & &quot;',&quot;
SQL = SQL & &quot; UserID='&quot; & myUserID & &quot;',&quot;
SQL = SQL & &quot; password='&quot; & myPwd & &quot;',&quot;
SQL = SQl & &quot; department='&quot; & myDept & &quot;',&quot;
SQL = SQL & &quot; yearinfo='&quot; & myYr & &quot;',&quot;
SQL = SQl & &quot; email='&quot; & myEmail & &quot;'&quot;

SQL = SQL & &quot; WHERE UserID=&quot; & myUserID

DataConn.execute(SQL)

if (Request(&quot;submit&quot;) <> &quot;&quot;) then
Response.Redirect (&quot;thank.asp&quot;)
else%>
<script>
window.alert (&quot;Records cannot be updated&quot;)
</script>
<%end if

DataConn.Close
Set DataConn = Nothing

%>


Thank You :cool:
 
You should really tell ASP what you are requesting - a form field ie. Request.Form(&quot;Field&quot;) or a part of the querystring ie. Request.Querystring(&quot;Field&quot;) and set the method in your <FORM> tag correspondingly.

either <FORM NAME=TheForm METHOD=POST>
or <FORM NAME = TheForm METHOD=GET>

If you don't it will run slower, as it checks both, and it could mean a potential security hole, as clients could tag a ?name=bla on to the URL and sneak this parameter into your code...

Also using the POST-method let's you submit more info than the GET...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top