View Single Post
  #1 (permalink)  
Old 06-22-2005, 03:55 PM
Jenny Jenny is offline
Registered User
 
Join Date: Jun 2005
Posts: 2
Question SQL Problem with INSERT

I have been trying to teach myself SQL and ASP. I can read from a database if the information is manually inserted into it by myself. But I have created a simple form to insert a person's first name into the database and it is not working! It will insert a record into the table but there will only be a "," in the field. The table that it is going into is also a simple table consisting of 1 field (FirstName). The field is of varchar data type and is not nullable since it is the primary key. I am using MS SQL Server 2000. Here is my code to my form page:

<html>

<head>
<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">
<link rel="stylesheet" href="Style_Sheet.css" Type="text/css">
<title>Title1</title>
</head>

<body>
<div id="pupads">
<table class="form">
<tr>
<td>
<form method="post" action="simple_respond.asp" enctype="multipart/form-data" name=frmAdd>
<table>
<tr>
<td><b>First Name*:</td>
<td>
<input type="varchar" name="FirstName" size="25" tabindex="1">
</td>
</tr>
<tr>
<td width="22%" align="right">
<input type="button" value="Submit" name="btnSubmit" tabindex="14"></td>
<td width="78%">
<input type="reset" value="Clear" name="B2" tabindex="15"></td>
</tr>
</table>
</form>
<SCRIPT LANGUAGE=vbscript>
Sub btnSubmit_OnClick
'Check required fields to make sure there is something in them
If Len (frmAdd.FirstName.value) = 0 Then
Alert "You must enter your first name"
frmAdd.FirstName.focus
Exit Sub
End If

Call frmAdd.Submit()
End Sub
</SCRIPT>

</td>
</tr>
</table>
</div>

<p class="break">&nbsp
</p>

<div id="cleardiv">
</div>
</div>
</div>
<div id="footer">
<!-- #include file="menus/footer.htm" -->
</div>

</body>

</html>

Here is the code for my response page:
<html>

<head>
<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">
<link rel="stylesheet" href="Style_Sheet.css" Type="text/css">
<title>Title1</title>
</head>

<body>

<%
dim oCon
dim oRS
dim strInsert

'Open the Connection
Set oCon = Server.CreateObject ("ADODB.connection")
oCon.Open "DSN=Simple;uid=;pwd="

'Execute INSERT INTO Query
strInsert = "INSERT INTO customers (FirstName) Values ('" & Cstr(Request.Form ("FirstName")) & "')"
oCon.Execute(strInsert)


oCon.Close
Set oCon = nothing

%>
<p class="break">&nbsp
</p>

<div id="cleardiv">
</div>
</div>
</div>
<div id="footer">
<!-- #include file="menus/footer.htm" -->
</div>

</body>

</html>

Help would really be appreciated!!!

Thanks,
Jenny