help with SQL Insert and delete

I

isaac2004

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/adovbs.inc"-->
<html>
<head><title>Using SQL to List, Insert & Delete Data</title></head>
<body>
<center>
<h3>Using SQL to List, Insert & Delete Data</h3>
Please enter a name:
<form>
<table>
<tr>
<td>
First Name:
</td>
<td>
<input type="textbox" name="strFirstName" size="20">
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<input type="textbox" name="strLastName" size="20">
<input type="submit" Name="AddName" text="Add Name"
Value="Add Person">
</td>
</tr>
</table>
</form>


<table border='1' cellpadding='3' cellspacing='0'
bordercolor='#BBDBE6'>
<tr>
<td><b>ID</b></td>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
<td><b>Delete</b></td>
</tr>



<%
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>"
%>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top