By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,761 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,761 IT Pros & Developers. It's quick & easy.

help with SQL Insert and delete

P: n/a
im trying to make a page that reads simple user information and posts
them to a table. the user can edit, delete and add new records, through

a form on the page.using SQLs modifications like insert and delete, how

would you go about doing this. the script executes an if then statment
that tests a submit button and initiates the insert portion of the SQL
statement .

here is the code i have so far
<% Option Explicit %>
<!--#include file="DatabaseConnect2.asp"-->
<!--#include virtual="/06Winter/levini/database/"-->
<head><title>Using SQL to List, Insert & Delete Data</title></head>
<h3>Using SQL to List, Insert & Delete Data</h3>
Please enter a name:
First Name:
<input type="textbox" name="strFirstName" size="20">
Last Name:
<input type="textbox" name="strLastName" size="20">
<input type="submit" Name="AddName" text="Add Name"
Value="Add Person">
<table border='1' cellpadding='3' cellspacing='0'
<td><b>First Name</b></td>
<td><b>Last Name</b></td>

dim objRS, strSQL, strLastName, strFirstName

function CleanIn(strIn)
strIn = replace(strIn, "'", " ")
CleanIn = replace(strIn, "<", " ")
end function
strFirstName = Request.querystring("strFirstName")
strLastName = Request.querystring("strLastName")
'Create a recordset object and execute the SQL statement
Set objRS = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT tblNames.PersonID, tblNames.strFirstName,
tblNames.strLastName " & _
"FROM tblNames " & _
"ORDER BY tblNames.PersonID "
objRS.Open strSQL, objConn
if request.querystring ("Add Name") > " " then

strSQL = "INSERT INTO tblNames (strFirstName, strLastName) " & _
"VALUES (CleanIn)('strFirstName')('strLastName')"

objRS.Open strSQL, objConn
end if

response.write("<TR><TD>" & objRS("PersonID") & "</TD>")
response.write("<TD>" & objRS("strFirstName") & "</TD>")
response.write("<TD>" & objRS("strLastName") & "</TD>")
response.write("<TD><a href='SQLInsertDelete.asp?DeleteID=" &
objRS("PersonID") & "'>Delete</a></TD></table>")

response.write "strSQL=" & strSQL & "<br>"


Feb 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.