Hi,
For a project of mine, I've implemented user registrations. However, one thing I have NOT implemented is the ability to check if the username requested by a new registration exists in the database. How do I do this? The code for the registration page is as below:

(btw, I would appreciate if the forum moderators could tell me how I should post huge blocks of code. Do I attach the file or just quote the code?)

<%@ Language="VBScript" %>
<%reg=Request("reg")%>
<%
if reg = 1 then
%>

<SCRIPT LANGUAGE="JavaScript">
alert("Registration Succeeded. Logging you in...")
</SCRIPT>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=/mediaguidehome.asp?user=<%=Request.Form("username")%>&pass=<%=Request.Form("output")%>">
<%
table=TRIM(Request.Form("UserName"))
Set con2 = server.CreateObject ("ADODB.Connection")
Set rs2  = server.CreateObject ("ADODB.Recordset")

con2.Provider="Microsoft.Jet.OLEDB.4.0"
con2.Open (server.MapPath ("\databasecore\mediaguide.mdb"))
sql2 = "INSERT INTO authenticatedusers VALUES "
sql2=sql2 & "('" & TRIM(Request.Form("username"))    & "',"
sql2=sql2 & "'" & TRIM(Request.Form("output"))        & "',"
sql2=sql2 & "'" & TRIM(Request.Form("name"))        & "',"
sql2=sql2 & "'" & TRIM(Request.Form("address"))  & "',"
sql2=sql2 & "'" & TRIM(Request.Form("Country"))       & "',"
sql2=sql2 & "'" & TRIM(Request.Form("age"))     & "',"
sql2=sql2 & "'" & TRIM(Request.Form("tel"))     & "',"
sql2=sql2 & "'" & TRIM(Request.Form("dateofbirth"))     & "',"
sql2=sql2 & "'" & TRIM(Request.Form("monthofbirth"))     & "',"
sql2=sql2 & "'" & TRIM(Request.Form("yearofbirth"))     & "',"
sql2=sql2 & "'" & TRIM(Request.Form("email"))       & "')"'
Con2.BeginTrans
Con2.Execute sql2
Con2.CommitTrans
Con2.Close

Set con1 = server.CreateObject ("ADODB.Connection")
Set rs1  = server.CreateObject ("ADODB.Recordset")

con1.Provider="Microsoft.Jet.OLEDB.4.0"
con1.Open (server.MapPath ("\databasecore\mediaguide.mdb"))

sql1="CREATE TABLE user_"&table&" (name VarChar(200), artist VarChar(200), album varChar(200), rating varChar(50), review Memo)"
rs1.Open sql1,con1

end if
%>

<HTML>
<HEAD>
<TITLE>Registration</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var str_in;
var str_out = "";
var num_in;
var num_out = "";
function str_to_num(form) {
num_out = "";
if(form.password.value == "") ;
else {
str_in = escape(form.password.value);
for(i = 0; i < str_in.length; i++) {
num_out += str_in.charCodeAt(i) - 23;
}

rannum=str_in.length+32
pwhash=rannum*num_out/100000000000
finalop=pwhash+rannum
form.output.value = finalop;
}
}
</script>
<SCRIPT>
function password()
{
window.open("passwordeg.htm", "","toolbar=no, height=650, width=600, directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
}
</SCRIPT>
<meta name="Microsoft Theme" content="folio 111, default">
</HEAD>
<BODY><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr>
<td width="100%">
<p align="right">
<!--webbot bot="Navigation" S-Type="banner" S-Orientation="horizontal" S-Rendering="graphics" --><br>
<font size="2">
<!--webbot bot="Navigation" S-Orientation="horizontal" S-Rendering="html" S-Bar="Bars" S-Btn-Nml="&lt;A HREF=&quot;#URL#&quot; TARGET=&quot;#TARGET#&quot; STYLE=&quot;{text-decoration: none;}&quot;&gt;#LABEL#&lt;/A&gt;" S-Btn-Sel="#LABEL#" S-Btn-Sep="&amp;nbsp;|&amp;nbsp;" S-Type="top" B-Include-Home="TRUE" B-Include-Up="FALSE" --></font></p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr>
<td width="50%">

<!--BEGIN JAVASCRIPT FOR FORM VALIDITY-->
<SCRIPT LANGUAGE="Javascript">
var digit="0123456789";
function val()
{
if(username_v() && password_v())
if(name_v() && add_v())
if(telno_v() && email_v())
return true;
return false;
}
function username_v()
{
if(document.auth.username.value=="")
{
alert("Please enter a valid username");
document.auth.username.focus();
return false;
}
return true;
}
function password_v()
{
if(document.auth.password.value=="")
{
alert("Please enter password");
document.auth.password.focus();
return false;
}
if(document.auth.cnfrmpwd.value=="")
{
alert("Please re-type password");
document.auth.cnfrmpwd.focus();
return false;
}
if(document.auth.password.value!=document.auth.cnfrmpwd.value)
{
alert("Please re-type password correctly");
document.auth.password.select();
document.auth.cnfrmpwd.value="";
return false;
}
return true;
}
function name_v()
{
if(document.auth.name.value=="")
{
alert("Please enter your name");
document.auth.name.focus();
return false;
}
return true;
}
function add_v()
{
if(document.auth.address.value=="")
{
alert("Please enter your address");
document.auth.address.focus();
return false;
}
if(document.auth.country.value=="")
{
alert("Please enter your country");
document.auth.country.focus();
return false;
}
if(document.auth.tel.value=="")
{
alert("Please enter your contact number");
document.auth.tel.focus();
return false;
}
if(document.auth.dateofbirth.value=="Date")
{
alert("Please select your Date of Birth");
document.auth.dateofbirth.focus();
return false;
}
if(document.auth.monthofbirth.value=="Month")
{
alert("Please select your Month of Birth");
document.auth.monthofbirth.focus();
return false;
}
if(document.auth.yearofbirth.value=="Year")
{
alert("Please select your Year of Birth");
document.auth.yearofbirth.focus();
return false;
}

if(document.auth.age.value=="")
{
alert("Please enter your Age");
document.auth.age.focus();
return false;
}
return true;
}
function telno_v()
{
if(document.auth.email.value=="")
{
alert("Please enter your email address");
document.auth.email.focus();
return false;
}
return true;
}
</script>

</td>
</tr>
</table></td>
</tr>
</table>
<p align="justify">In order to&nbsp; access the features of this site (including reviews, previews and artist
information) we need you to give us a few details about yourself. Please fill in
all the fields provided and then click &quot;Register&quot; to complete the registration
process. Note that if you are a member of our Media Guide, <a href="/signin.asp">you can use the same ID to login</a>. </p>
<p align="justify">Section 1: Login Information </p>
<blockquote>
<blockquote>
<p align="justify">In this section, you will be asked to enter a unique username
and password for identifying yourself to us. Please note that passwords are case
sensitive, so make sure you use the correct case.</p>
</blockquote>
</blockquote>
<!-- -->
<form name="auth" onSubmit="return val()" action="register.asp?reg=1" method="post">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="82%" height="45">
<tr>
<td width="100%" align="center" height="45" colspan="2">
<p align="center">Username: <input type="text" size="30" name="username"></p>
</td>
</tr>
<tr>
<td width="50%" align="center" height="45">
<blockquote>
<blockquote>
<blockquote>
<p align="justify">Password:<br>
<input type="password" size="30" name="password" maxlength="15"></blockquote>
</blockquote>
</blockquote>
</td>
<td width="50%" align="center" height="45">
<blockquote>
<blockquote>
<blockquote>
<p align="justify">Confirm Password:<br>
<input type="password" size="30" name="cnfrmpwd" maxlength="15">
<input type="hidden" size="30" name="output"></blockquote>
</blockquote>
</blockquote>
</td>
</tr>
</table>
</center>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<ul>
<li>
<p align="left"><font size="2">Passwords are case sensitive</font></li>
<li>
<p align="left"><font size="2">Ensure the password length is of 8 characters minimum
and 15 characters maximum [<a href="javascript:password()">What's this?</a>]</font></li>
</ul>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<hr>
</blockquote>
</blockquote>
<p align="justify">Section 2: Personal Information</p>
<blockquote>
<blockquote>
<p align="justify">In this section, we require you to fill out a few
personal details for our records. We will not sell or give out your personal
information to any third party.</p>
</blockquote>
</blockquote>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr>
<td width="50%" valign="top" align="center">Name:<br>
<input type="text" size="30" name="name"><p>Date of Birth:<br>
<select size="1" name="dateofbirth">
<option selected>Date</option>
<option>--------</option>
<%
dat=1
while dat<=31
%>
<option value="<%=dat%>"><%=dat%></option>
<%
dat=dat + 1
Wend
%>
</select> / <select size="1" name="monthofbirth">
<option selected>Month</option>
<option>------------------</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select> / <select size="1" name="yearofbirth">
<option selected>Year</option>
<option>--------</option>
<%
yr=1950
while yr<=2002
%>
<option value="<%=yr%>"><%=yr%></option>
<%
yr=yr + 1
Wend
%>
</select></p>
<p>Age:<br>
<input type="text" size="30" name="age"></p>
<p>&nbsp;</td>
<td width="50%" valign="top" align="center">E-Mail Address: <br>
<input type="text" size="30" name="email"><p>Country: <br>
<input type="text" size="30" name="country"></p>
<p>Contact Number: <br>
<input type="text" size="30" name="tel"><br>
&nbsp;</td>
</tr>
</table>
<br>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr>
<td width="100%">
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p style="text-align: left">Address:</p>
<blockquote>
<p style="text-align: left">
<textarea rows="10" cols="36" name="address"></textarea></p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<p>&nbsp;</td>
</tr>
</table>
<p>
You're done. Just click the register button to continue.<p>
<input type="submit" value="Register" onClick="javascript:str_to_num(this.form)">
<input type="reset" value="Reset"> <input type="button" value="Cancel" name="B1" onclick="location.href('/mediaguidehome.asp')"></FORM>
</HTML>

Thanks

the easiest way is to run a resordset with the details as where clauses. then have an if the recordset is empty then insert new records else redirect to a page that says those details exist

the other thing is, im not sure about the others but since you are asking about an asp problem only put the asp code. and maybe the relevant form

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.