help with SQL Insert and delete

Discussion in 'ASP General' started by isaac2004, Feb 13, 2006.

  1. isaac2004

    isaac2004 Guest

    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>
     
    isaac2004, Feb 13, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    7,881
    elizas
    Apr 27, 2010
  2. Shapper
    Replies:
    3
    Views:
    573
    Scott Allen
    Jul 9, 2005
  3. Harry Zoroc
    Replies:
    1
    Views:
    996
    Gregory Vaughan
    Jul 12, 2004
  4. Steve
    Replies:
    0
    Views:
    468
    Steve
    Dec 3, 2006
  5. Belinda
    Replies:
    4
    Views:
    395
    Bob Barrows [MVP]
    Jun 11, 2004
Loading...

Share This Page