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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating information in the database.

Status
Not open for further replies.

LucyL

Technical User
Feb 20, 2002
113
US
Hi,
I am new to VBScript and want to be able to update information in the database. Currently I have this code for the inserting. I am unsure of what syntax I will use to update details already in the database. Is it just the sql statement I use based on whatever the user logs in as?

<%@ Language = VBScript%>
<%Response.buffer=true%>


<html>

<head>
<title>Register</title>
<link rel=&quot;stylesheet&quot; href=&quot;Stylesheet.css&quot; type =&quot;text/css&quot;>
<script>
function validateInput()
{
var uname = window.document.register.uname.value;
var password = window.document.register.password.value;
var confirmpassword = window.document.register.confirmpassword.value;
var email = window.document.register.email.value;
var favorite = window.document.register.favorite.selectedIndex;

if(uname==(&quot;&quot;))
{
alert(&quot;Please enter your Username!&quot;)
register.uname.focus();
return false;
}

if(password==(&quot;&quot;))
{
alert(&quot;Please enter your password!&quot;)
register.password.focus();
return false;
}

if(confirmpassword==(&quot;&quot;))
{
alert(&quot;Please enter password again for confirmation!&quot;)
register.confirmpassword.focus();
return false;
}


if(email==(&quot;&quot;))
{
alert(&quot;Please enter your Email Address!&quot;)
register.email.focus();
return false;
}

if(email.indexOf(&quot;@&quot;)==-1||email.indexOf(&quot;.&quot;)==-1)
{
alert(&quot;Please enter a valid Email Address!&quot;);
register.email.focus();
return false;
}

if (favorite == &quot;&quot;)
{
alert(&quot;Please select your preferred console!&quot;)
window.document.register.favorite.focus()
return false;
}

}
</script>
<%
'Declare the variables
Dim form_uname
Dim form_password
Dim form_email
Dim form_favorite

Set dbCon = Server.CreateObject(&quot;ADODB.Connection&quot;)
dbCon.Open(&quot;DSN=BISDATA;UID=98279335;PWD=grinleahy&quot;)

sub details()
'Assign values entered by users to these variables
form_uname = request.form(&quot;uname&quot;)
form_password = request.form(&quot;password&quot;)
form_email = request.form(&quot;email&quot;)
form_favorite = request.form(&quot;favorite&quot;)

Dim sqlStatement
sqlStatement = &quot;INSERT INTO user_table(user_name, password, email_address, favorite) values('&quot;&(form_uname)&&quot;', '&quot;&(form_password)&&quot;', '&quot;&(form_email)&&quot;', '&quot;&(form_favorite)&&quot;';&quot;

dbCon.Execute(sqlStatement)

end sub
Details()


%>


</head>

<body>
<form name = &quot;register&quot; action = &quot;register.asp&quot; method = &quot;post&quot;>
<!--<form name = &quot;register&quot; method = &quot;get&quot; action = &quot;register.htm&quot;>-->

<table bgcolor = &quot;#FFFFFF&quot; bordercolor = &quot;#CC3333&quot; border = 1.5 width = 100%>
<tr><td><font color =&quot;#CC3333&quot; align = &quot;right&quot;><h1>GamePro.com</h1></font></td></tr>
</table>

<!--Enter personal details to register-->
<h3><font color = &quot;#CC33333&quot;>Please enter the following details:</font></h3>
<table width = 33%>
<tr><td><font color = &quot;#CC3333&quot;><b>Username:</b></font></td></tr>
<tr><td><input type=&quot;text&quot; name=&quot;uname&quot;></td></tr>
<tr><td><font color = &quot;#CC3333&quot;><b>Password:</b></font></td></tr>
<td><input type=&quot;text&quot; name=&quot;password&quot;></td></tr>
<tr><td><font color = &quot;#CC3333&quot;><b>Reconfirm password:</b></font></td></tr>
<tr><td><input type=&quot;text&quot; name=&quot;confirmpassword&quot;></td></tr>
<tr><td><font color = &quot;#CC3333&quot;><b>Email Address:</b></font></td></tr>
<tr><td><input type = &quot;text&quot; name = &quot;email&quot;></td></tr>
<tr><td><img border=&quot;0&quot; src=&quot;regist1.gif&quot; width=&quot;177&quot; height=&quot;16&quot;></td></tr>
<tr><td><select name=&quot;favorite&quot; size = 1>
<option>Sega</option>
<option>Playstation</option>
<option>Nintendo</option>
<option>Sony</option>
<option>Dreamcast</option>
</select></td></tr>
<br>
<br>
</table>

<input type=&quot;submit&quot; onclick=&quot;return validateInput();&quot; value=&quot;Register Now!&quot;>
<input type=&quot;reset&quot; value=&quot;Reset&quot;>

<br><br>
<a href = Homepage.htm>HOME</a>


</BODY>
</HTML>














 
lucyl,

You can use the ADO connection to update you record.

strSQL = &quot;SELECT * FROM usertable WHERE userid='&quot; & form_uname & &quot;'&quot;
dbcon.Execute(strSQL)

if dbcon.recordcount = 1 then
dbcon(&quot;favorite&quot;) = form_favorite
dbcon(&quot;password&quot; = form_password
dbcon.update
endif


Cheers,
fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top