| | |
SQL Query inserts junk data as well
Please support our ASP advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
Hi all,
here's a bit of code for a registration page im working on.
Now the problem is, whenever I click submit, the form data is posted in the database. However, in addition to that, 2-3 new blank records are entered as well. So, if I insert a new record, a total of 3-4 records are inserted. This has me stumped. Any ideas? Thanks.
here's a bit of code for a registration page im working on.
•
•
•
•
<%@ Language="VBScript" %>
<%reg=Request("reg")%>
<%
if reg <> 0 then
%>
<SCRIPT LANGUAGE="JavaScript">
alert("Confirmed. The information has been entered.")
</SCRIPT>
<%
End If
Set Con = Server.CreateObject ("ADODB.Connection")
Set rs = server.CreateObject ("ADODB.Recordset")
Con.Provider="Microsoft.Jet.OLEDB.4.0"
Con.Open(Server.MapPath("cesa.mdb"))
sql = "INSERT INTO memberdetails VALUES "
sql=sql & "('" & TRIM(Request.Form("ApplicationNumber"))& "',"
sql=sql & "'" & TRIM(Request.Form("FormNumber"))& "',"
sql=sql & "'" & TRIM(Request.Form("name"))& "',"
sql=sql & "'" & TRIM(Request.Form("dateofbirth"))& "',"
sql=sql & "'" & TRIM(Request.Form("address"))& "',"
sql=sql & "'" & TRIM(Request.Form("phone"))& "',"
sql=sql & "'" & TRIM(Request.Form("mobile"))& "',"
sql=sql & "'" & TRIM(Request.Form("email"))& "',"
sql=sql & "'" & TRIM(Request.Form("MemberOfOtherCommittee"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfOtherCommittee"))& "',"
sql=sql & "'" & TRIM(Request.Form("TechExposure"))& "',"
sql=sql & "'" & TRIM(Request.Form("DetailsOfTechExposure"))& "',"
sql=sql & "'" & TRIM(Request.Form("Hobbies"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfSchool"))& "',"
sql=sql & "'" & TRIM(Request.Form("SSCPercentage"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfJuniorCollege"))& "',"
sql=sql & "'" & TRIM(Request.Form("HSCPercentage"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfDiplomaCollege"))& "',"
sql=sql & "'" & TRIM(Request.Form("DiplomaPercentage"))& "',"
sql=sql & "'" & TRIM(Request.Form("DiplomaBranch"))& "',"
sql=sql & "'" & TRIM(Request.Form("YearOfEngg"))& "',"
sql=sql & "'" & TRIM(Request.Form("OtherCoursesAttended"))& "',"
sql=sql & "'" & TRIM(Request.Form("AmountPaid"))& "',"
sql=sql & "'" & TRIM(Request.Form("DateOfRegistration"))& "')"'
rs.Open sql,con
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Computer Engineering Students Association</title>
<SCRIPT>
function reset()
{
document.details.reset()
}
</SCRIPT>
<meta name="Microsoft Theme" content="network 011">
</head>
<body onload=reset()>
<p>
<tr>
<td width="24%"></td> <td width="76%"><table border="0" cellspacing="1" style="border-collapse: collapse" width="100%" height="165">
<tr>
<td width="22%" height="162">
<img border="0" src="CESA_final%20logo_form.gif" width="246" height="182"></td>
<td width="78%" height="162">
<FORM NAME="details" action="cesa.asp?reg=1" method="post">
<h1 align="center"><b><b><font face="Nasalization" style="font-size: 40pt">
Computer Engineering Students Association</font></b></b></h1>
<p align="right">Application No.<input type="text" size="5" name="ApplicationNumber"><br>
Form No.<input type="text" size="5" name="FormNumber"></td>
</tr>
</table></td>
</tr>
</table>
<p align="center"><b><u><font size="5">Member database
entry form</font></u></b><hr>
<b>
<table border="1" cellspacing="1" style="border-collapse: collapse" width="100%">
<tr>
<td width="100%" colspan="4" bgcolor="#000000">
<p align="center"><b><font face="Trebuchet MS" color="#FFFFFF">Personal
Details</font></b></td>
</tr>
<tr>
<td width="25%">Full Name</td>
<td width="25%"><b>
<input type="text" size="47" name="name"></b></td>
<td width="25%">Date of Birth</td>
<td width="25%"><b>
<input type="text" size="28" name="dateofbirth"></b></td>
</tr>
<tr>
<td width="25%">Address</td>
<td width="75%" colspan="3">
<p align="left"><textarea rows="9" cols="71" name="address"></textarea></td>
</tr>
<tr>
<td width="25%">Phone Number</td>
<td width="25%"><input type="text" size="37" name="phone"></td>
<td width="14%" rowspan="2">E-Mail Address</td>
<td width="36%" rowspan="2"><input type="text" size="43" name="email"></td>
</tr>
<tr>
<td width="25%">Mobile Number</td>
<td width="25%"><input type="text" size="37" name="mobile"></td>
</tr>
</table>
<table border="1" cellspacing="1" style="border-collapse: collapse" width="100%" height="247">
<tr>
<td width="38%" height="24">Are you a member of any other committee?</td>
<td width="8%" height="24">
<input type="radio" name="MemberOfOtherCommittee" value="Yes">Yes </td>
<td width="7%" height="24">
<input type="radio" name="MemberOfOtherCommittee" value="No">No </td>
<td width="58%" height="24">If yes, please specify
<input type="text" size="29" name="NameOfOtherCommittee"></td>
</tr>
<tr>
<td width="38%" height="20">Have you had exposure to a technical background?</td>
<td width="8%" height="20">
<input type="radio" name="TechExposure" value="Yes">Yes</td>
<td width="7%" height="20">
<input type="radio" name="TechExposure" value="No">No</td>
<td width="58%" height="20">If yes, please specify
<input type="text" size="29" name="DetailsOfTechExposure"></td>
</tr>
<tr>
<td width="111%" colspan="4" height="192">List Your Hobbies and Interests:<blockquote>
<p align="center"><textarea rows="8" cols="91" name="Hobbies"></textarea></p>
</blockquote>
</td>
</tr>
</table>
<table border="1" cellspacing="1" style="border-collapse: collapse" width="100%">
<tr>
<td width="100%" colspan="4" bgcolor="#000000" align="center"><b>
<font face="Trebuchet MS" color="#FFFFFF">Educational Experience</font></b></td>
</tr>
<tr>
<td width="31%">Name of School</td>
<td width="69%" colspan="3">
<input type="text" size="29" name="NameOfSchool"></td>
</tr>
<tr>
<td width="31%">Percentage obtained in SSC</td>
<td width="69%" colspan="3">
<input type="text" size="29" name="SSCPercentage"></td>
</tr>
<tr>
<td width="31%">Name of Junior College</td>
<td width="69%" colspan="3">
<input type="text" size="29" name="NameOfJuniorCollege"></td>
</tr>
<tr>
<td width="31%">Percentage obtained in HSC</td>
<td width="69%" colspan="3">
<input type="text" size="29" name="HSCPercentage"></td>
</tr>
<tr>
<td width="31%">If Diploma, name of diploma college</td>
<td width="69%" colspan="3">
<input type="text" size="29" name="NameOfDiplomaCollege"></td>
</tr>
<tr>
<td width="31%">Percentage in diploma</td>
<td width="23%"><input type="text" size="29" name="DiplomaPercentage"></td>
<td width="23%">Branch selected</td>
<td width="23%"><input type="text" size="29" name="DiplomaBranch"></td>
</tr>
<tr>
<td width="31%">What year of engineering are you in now?</td>
<td width="69%" colspan="3"> <input type="radio" name="YearOfEngg" value="First">First Year<b><input type="radio" name="YearOfEngg" value="Second"></b> Second
Year<b><input type="radio" name="YearOfEngg" value="Third"></b> Third Year<b><input type="radio" name="YearOfEngg" value="Final"></b> Final
Year</td>
</tr>
<tr>
<td width="100%" colspan="4">
<p class="BodyText4">Please list any other courses you may have attended:</p>
<blockquote>
<p class="BodyText4" align="center"> <textarea rows="8" cols="91" name="OtherCoursesAttended"></textarea> </p>
</blockquote>
</td>
</tr>
</table>
</b>
<table border="1" cellspacing="1" style="border-collapse: collapse" width="100%">
<tr>
<td width="16%">Amount Paid</td>
<td width="21%"><span style="font-weight: normal">
Rs.
<input type="text" size="8" name="AmountPaid"> /-</span></td>
<td width="25%">Date of Registration</td>
<td width="38%">
<input type="text" size="24" name="DateOfRegistration"></td>
</tr>
</table> <p>
<input type="Submit" value="Submit">
<input type="Reset" value="Reset"> </p>
</FORM>
</body>
</html>
Now the problem is, whenever I click submit, the form data is posted in the database. However, in addition to that, 2-3 new blank records are entered as well. So, if I insert a new record, a total of 3-4 records are inserted. This has me stumped. Any ideas? Thanks.
Touch eyeballs to screen for cheap laser surgery
•
•
Join Date: Sep 2004
Posts: 89
Reputation:
Solved Threads: 1
•
•
•
•
well, the sql insert runs everytime the page loads, regardless of whether or not there is any information, so if the page gets called directly, instead of someone typing in information in your form and hitting submit, it is going to insert a blank row.
<%@ Language="VBScript" %>
<%reg=Request("reg")%>
<%
if reg <> 0 then
%>
<SCRIPT LANGUAGE="JavaScript">
alert("Confirmed. The information has been entered.")
</SCRIPT>
<%
Set Con = Server.CreateObject ("ADODB.Connection")
Set rs = server.CreateObject ("ADODB.Recordset")
Con.Provider="Microsoft.Jet.OLEDB.4.0"
Con.Open(Server.MapPath("cesa.mdb"))
sql = "INSERT INTO memberdetails VALUES "
sql=sql & "('" & TRIM(Request.Form("ApplicationNumber"))& "',"
sql=sql & "'" & TRIM(Request.Form("FormNumber"))& "',"
sql=sql & "'" & TRIM(Request.Form("name"))& "',"
sql=sql & "'" & TRIM(Request.Form("dateofbirth"))& "',"
sql=sql & "'" & TRIM(Request.Form("address"))& "',"
sql=sql & "'" & TRIM(Request.Form("phone"))& "',"
sql=sql & "'" & TRIM(Request.Form("mobile"))& "',"
sql=sql & "'" & TRIM(Request.Form("email"))& "',"
sql=sql & "'" & TRIM(Request.Form("MemberOfOtherCommittee"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfOtherCommittee"))& "',"
sql=sql & "'" & TRIM(Request.Form("TechExposure"))& "',"
sql=sql & "'" & TRIM(Request.Form("DetailsOfTechExposure"))& "',"
sql=sql & "'" & TRIM(Request.Form("Hobbies"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfSchool"))& "',"
sql=sql & "'" & TRIM(Request.Form("SSCPercentage"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfJuniorCollege"))& "',"
sql=sql & "'" & TRIM(Request.Form("HSCPercentage"))& "',"
sql=sql & "'" & TRIM(Request.Form("NameOfDiplomaCollege"))& "',"
sql=sql & "'" & TRIM(Request.Form("DiplomaPercentage"))& "',"
sql=sql & "'" & TRIM(Request.Form("DiplomaBranch"))& "',"
sql=sql & "'" & TRIM(Request.Form("YearOfEngg"))& "',"
sql=sql & "'" & TRIM(Request.Form("OtherCoursesAttended"))& "',"
sql=sql & "'" & TRIM(Request.Form("AmountPaid"))& "',"
sql=sql & "'" & TRIM(Request.Form("DateOfRegistration"))& "')"'
rs.Open sql,con
End If
%>![]() |
Similar Threads
- sql query problem with MS Access and C# (C#)
- retrieving a particular value with a sql query (PHP)
- SQL query problem with WHERE clause (ASP)
- C# VS 2005 - SQL Query Parameters to an ODBC DataSource (C#)
- PHP/SQL query help (PHP)
- Retreiving variables from a sql query into a form (PHP)
Other Threads in the ASP Forum
- Previous Thread: login
- Next Thread: MS Excel data to ASP form
| Thread Tools | Search this Thread |
archive asp aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection






