Click to See Complete Forum and Search --> : Adding a record to the database???


al_3asel
07-20-2004, 06:02 AM
Hi all,

I'm asking for adding a record to the database which that's record already available in the database. In this case an error must dislplay for the user to tell him that your record is already availble.....

this is my code and I tried

<HTML><HEAD>


<%
Function ChkString(str)

str = replace(str, "<", "&lt;", 1, -1, 1)
str = replace(str, ">", "&gt;", 1, -1, 1)

ChkString = str
End Function

name = trim(ChkString(Request.form("name")))
email = trim(ChkString(Request.form("email")))
address = trim(ChkString(Request.form("address")))
City = trim(ChkString(Request.form("city")))
State = trim(ChkString(Request.form("state")))
Country = trim(ChkString(Request.form("country")))
Zipcode = trim(ChkString(Request.form("zip")))
Password = trim(ChkString(Request.form("password")))
confirmpassword = trim(ChkString(request.form("confirmpassword")))


if name = "" then
Response.Write "Please Enter Your name<br>"
else

if email = "" then
Response.Write "Please Enter valid email<br>"
else

if address = "" then
Response.Write "Please Enter valid Address<br>"
else

if city = "" then
Response.Write "Please Enter City<br>"
else

if State = "" then
Response.Write "Please Enter State<br>"
else

if country = "" then
Response.Write "Please select country<br>"
else

if zipcode = "" then
Response.Write "Please Enter zip code<br>"
else


if password = "" then
Response.Write "Please Enter password<br>"
else

if password <> confirmpassword then
Response.Write "Password does not match"
else
%>


</HEAD>
<BODY bgColor=#f4f4f4>


<P align=center><font
color=#000000><strong>Please verify if all your info you supplied is correct!
If not hit back and correct.</strong></font></P>



<center>

<table border="0" cellpadding="2" cellspacing="3" width="400">
<tr>
<td ><font face="Verdana" size="2" color=#000000>Name :</font></td>
<td ><%=name%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>E-mail :</font></td>
<td ><%=email%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>address :</font></td>
<td ><%=address%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>city :</font></td>
<td ><%=city%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>state :</font></td>
<td ><%=state%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>country :</font></td>
<td ><%=country%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>zip code :</font></td>
<td ><%=zipcode%>&nbsp;</td>
</tr>
<tr>
<td ><font face="Verdana" size="2" color=#000000>Password :</font></td>
<td ><%=password%>&nbsp;</td>
</tr>
<tr>
<td ><font color="#000000">&nbsp;</font></td>
<td > <form action=addnewmember.asp method="post">
<input type=hidden name="name"value="<%=name%>">
<input type=hidden name="email" value="<%=email%>">
<input type=hidden name="address" value="<%=address%>">
<input type=hidden name="city" value="<%=city%>">
<input type=hidden name="state" value="<%=state%>">
<input type=hidden name="country" value="<%=country%>">
<input type=hidden name="zip" value="<%=zipcode%>">
<input type=hidden name="password" value="<%=password%>">
<br>
<input type=submit value="Confirm">
</form></td>
</tr>
</table>
</center>


<%
end if
end if
end if
end if
end if
end if
end if
end if
end if



%></body></HTML>

zingmatter
07-20-2004, 10:45 AM
Crikey, lots wrong here.

Firstly, ou can't response.write inside the <head> region.

Where is the data stored that you want to check against? If it is in a database then you need to connect to the database, look for any matching records and if there is then update that record, or if there isn't then insert the new record.

I would recommend you use client-side javascript to validate the form. That way the form doesn't get sent until all the approiate fields have been filled, rather than have to make a round trip and get the user to re-fill the form (on some browsers hitting the back button might clear all the fields).