Link to home
Start Free TrialLog in
Avatar of Stiebel Eltron
Stiebel EltronFlag for Thailand

asked on

How to add DELETE action in an ASP page?

</head>

<body bgproperties="fixed" bgcolor="#000000" onLoad="javascript:startmenu()">

<%
	Dim myConnection
	Dim rsUsers
	Dim connectString
	Dim sqlString
	Dim requestName

	connectString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=DBSERVER; PORT=3306; DATABASE=DB; USER=DBUSER; PASSWORD=DBPW; OPTION=0;"

	Set myConnection = Server.CreateObject("ADODB.Connection")
	Set rsUsers = Server.CreateObject("ADODB.Recordset")

	myConnection.Open connectString

	requestName = Request.Form("USERID")
	response.Write(requestName)

	sqlString = "Select * From users WHERE ID = 1"
	
	Set rsUsers = myConnection.Execute(sqlString)

%>

<table width="760" border="0" cellspacing="3" cellpadding="1">
  <tr>
    <td width="134"><img src="../IMG/logo_res.jpg" alt="STIEBEL ELTRON" /></td>
    <td width="620" valign="top" bgcolor="#666666"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="548" height="197">
      <param name="movie" value="homeintro20.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <embed src="homeintro20.swf" quality="high" wmode="opaque" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="548" height="197"></embed>
    </object></td>
    <td width="134" bgcolor="#FFFFFF"><img src="../IMG/RegIcon.png" alt="ASIA" border="0" align="top"/></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right" bgcolor="#999999"><font face="Verdana, Geneva, sans-serif" color="#ffffff">
    <%
   '// If user is logged in show name and logout link
   If Session("loggedin") = true Then
      Response.Write "Welcome: " & Session("FName")
      Response.Write "<br /><a href=""../asia2/login/logout.asp"">Logout</a>"
   Else
      Response.Write "<a href=""../ste-iphoto-login2.asp"" title=""CLICK TO LOGIN"">REGISTERED USERS</a>"
   End If
	%>&nbsp;
	</td>
    <td bgcolor="#666666" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="left" bordercolor="#999999" bgcolor="#000000"><img src="../IMG/member.jpg" width="548" /><br></td>
    <td bgcolor="#999999" valign="top" align="center" rowspan=13>&nbsp;
		
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
    	<table width="100%" border="1" bordercolor="#cccccc" cellpadding="0" bgcolor="#999999">
    		<form name="form" id="form" method="post" action="#" onSubmit="return checkform(this)">
			<!--Get DATA-->
		<% do while not rsUsers.EOF %>
    		<tr>
        		<td class="td1" width="23%" align="right">First Name:</td>
           		<td class="td2" width="77%"><%=rsUsers("FName")%></td>
        	</tr>
    		<tr>
        		<td class="td1" width="23%" align="right">Last Name:</td>
           		<td class="td2" width="77%"><%=rsUsers("LName")%>
                </td>
        	</tr>
           	<tr>
        		<td class="td1" width="23%" align="right">Email:</td>
           		<td class="td2" width="77%"><%=rsUsers("Email")%>
            	</td>
        	</tr>

      
    		<tr>
        		<td class="td1" width="23%" align="right">Password:</td>
           		<td class="td2" width="77%"><%=rsUsers("Password")%>
                </td>
        	</tr>
        	<tr>
        		<td class="td1" width="23%" align="right">Country:</td>
           		<td class="td2" width="77%"><%=rsUsers("Country")%>
         	   </td>
        	</tr>
	        <tr>
    	    	<td class="td1" width="23%" align="right">Telephone:</td>
        	   	<td class="td2" width="77%"><%=rsUsers("Telephone")%>
                </td>
        	</tr>
        	<tr>
        		<td class="td1" width="23%" align="right">Mobile:</td>
           		<td class="td2" width="77%"><%=rsUsers("Mobile")%>
                </td>
        	</tr>
	    	<tr>
    	    	<td class="td1" width="23%" align="right">Company:</td>
        	   	<td class="td2" width="77%"><%=rsUsers("Company")%>
                </td>
        	</tr>
    		<tr valign="top">
        		<td class="td1" width="23%" align="right">Address:</td>
           		<td class="td2" width="77%"><%=rsUsers("Address")%></td>
        	</tr>
    		<tr valign="top">
        		<td class="td1" width="23%" align="right">Activate:</td>
           		<td class="td2" width="77%"><input type="radio" name="Activate" id="Yes"/>&nbsp;YES&nbsp;&nbsp;<input type="radio" name="Activate" id="No" />NO</td>
        	</tr>
            
	        <tr>
        		<td class="td" width="23%" align="right">&nbsp;</td>
           		<td width="77%"><input name="Submit" type="submit" value="UPDATE" onclick="return checkform();" />&nbsp;
                <input name="Delete" type="submit" value="DELETE" onclick="return checkform();" />
                </td>
        	</tr>
			


        </form>
        
       <% rsUsers.MoveNext %>
<%loop %><!--Next Row-->
    </table>

Open in new window


Dear EE experts,

Please see the attached embed scripts, we would like to ask for tech support on how to add a delete action on the same page.
If you click the delete button, the action should delete that item and update the database as well, then will refresh and redirects to another page...

Thank you in advance and hope to hear soon...
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

There are multiple ways to do this but here you create two forms. One for update and one for delete.
<%
If request.form("UpdateRecord")<>"" then
	'Place your UPDATE script here
end if
If request.form("UpdateRecord")<>"" then
	'Place your DELETE script here
end if
%>
<head>
</head>

<body bgproperties="fixed" bgcolor="#000000" onLoad="javascript:startmenu()">



<%
	Dim myConnection
	Dim rsUsers
	Dim connectString
	Dim sqlString
	Dim requestName

	connectString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=DBSERVER; PORT=3306; DATABASE=DB; USER=DBUSER; PASSWORD=DBPW; OPTION=0;"

	Set myConnection = Server.CreateObject("ADODB.Connection")
	Set rsUsers = Server.CreateObject("ADODB.Recordset")

	myConnection.Open connectString

	requestName = Request.Form("USERID")
	response.Write(requestName)

	sqlString = "Select * From users WHERE ID = 1"
	
	Set rsUsers = myConnection.Execute(sqlString)

%>

<table width="760" border="0" cellspacing="3" cellpadding="1">
  <tr>
    <td width="134"><img src="../IMG/logo_res.jpg" alt="STIEBEL ELTRON" /></td>
    <td width="620" valign="top" bgcolor="#666666"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="548" height="197">
      <param name="movie" value="homeintro20.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <embed src="homeintro20.swf" quality="high" wmode="opaque" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="548" height="197"></embed>
    </object></td>
    <td width="134" bgcolor="#FFFFFF"><img src="../IMG/RegIcon.png" alt="ASIA" border="0" align="top"/></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right" bgcolor="#999999"><font face="Verdana, Geneva, sans-serif" color="#ffffff">
    <%
   '// If user is logged in show name and logout link
   If Session("loggedin") = true Then
      Response.Write "Welcome: " & Session("FName")
      Response.Write "<br /><a href=""../asia2/login/logout.asp"">Logout</a>"
   Else
      Response.Write "<a href=""../ste-iphoto-login2.asp"" title=""CLICK TO LOGIN"">REGISTERED USERS</a>"
   End If
	%>&nbsp;
	</td>
    <td bgcolor="#666666" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="left" bordercolor="#999999" bgcolor="#000000"><img src="../IMG/member.jpg" width="548" /><br></td>
    <td bgcolor="#999999" valign="top" align="center" rowspan=13>&nbsp;
		
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
    	
    	<table width="100%" border="1" bordercolor="#cccccc" cellpadding="0" bgcolor="#999999">
    		
			<!--Get DATA-->
		<% do while not rsUsers.EOF %>
    		<tr>
        		<td class="td1" width="16%" align="right">First Name:</td>
           		<td colspan="2" class="td2"><%=rsUsers("FName")%></td>
        	</tr>
    		<tr>
        		<td class="td1" width="16%" align="right">Last Name:</td>
           		<td colspan="2" class="td2"><%=rsUsers("LName")%>
                </td>
        	</tr>
           	<tr>
        		<td class="td1" width="16%" align="right">Email:</td>
           		<td colspan="2" class="td2"><%=rsUsers("Email")%>
            	</td>
        	</tr>

      
    		<tr>
        		<td class="td1" width="16%" align="right">Password:</td>
           		<td colspan="2" class="td2"><%=rsUsers("Password")%>
                </td>
        	</tr>
        	<tr>
        		<td class="td1" width="16%" align="right">Country:</td>
           		<td colspan="2" class="td2"><%=rsUsers("Country")%>
         	   </td>
        	</tr>
	        <tr>
    	    	<td class="td1" width="16%" align="right">Telephone:</td>
        	   	<td colspan="2" class="td2"><%=rsUsers("Telephone")%>
                </td>
        	</tr>
        	<tr>
        		<td class="td1" width="16%" align="right">Mobile:</td>
           		<td colspan="2" class="td2"><%=rsUsers("Mobile")%>
                </td>
        	</tr>
	    	<tr>
    	    	<td class="td1" width="16%" align="right">Company:</td>
        	   	<td colspan="2" class="td2"><%=rsUsers("Company")%>
                </td>
        	</tr>
    		<tr valign="top">
        		<td class="td1" width="16%" align="right">Address:</td>
           		<td colspan="2" class="td2"><%=rsUsers("Address")%></td>
        	</tr>
    		<tr valign="top">
        		<td class="td1" width="16%" align="right">Activate:</td>
           		<td width="25%" rowspan="2" class="td2">
                <form>
                <table width="130" border="0" cellspacing="0" cellpadding="1">
           		  <tr>
           		    <th width="128" scope="col"><input type="radio" name="Activate" id="Yes"/>
           		      YES
           		      <input type="radio" name="Activate" id="No" />
           		      NO</th>
       		      </tr>
           		  <tr>
           		    <td align="center"><input name="UpdateRecord" type="hidden" id="CurrentRecord" value="<%=CurrentRecordID%>">           		      <input name="Submit" type="submit" value="UPDATE" onClick="return checkform();" /></td>
       		      </tr>
       		    </table>    
                </form>
                       		  &nbsp;</td>
           		<td width="59%" rowspan="2" class="td2">
                <form id="frmDelete">
                <table width="130" border="0" cellspacing="0" cellpadding="1">
           		  <tr>
           		    <th width="128" scope="col"><input name="DeleteRecord" type="hidden" id="CurrentRecord" value="<%=CurrentRecordID%>"></th>
       		      </tr>
           		  <tr>
           		    <td align="center"><input name="Submit" type="submit" value="Delete"  /></td>
       		      </tr>
       		    </table>
                </form>
                </td>
        	</tr>
            
	        <tr>
        		<td class="td" width="16%" align="right">&nbsp;</td>
       		</tr>
			


        </form>
        
       <% rsUsers.MoveNext %>
<%loop %><!--Next Row-->
</table>

Open in new window

Avatar of Stiebel Eltron

ASKER

Hi there Padas!
Regarding to the script you advised at the top, we need to put it @ the most top, before <HTML> right?

and for the 'Place your UPDATE / DELETE script, do u mean its message or its script?

and your answer is also the same to our another open thread, right?
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for the delayed response, because out of office, anyway, we would like to give u points now then will open a new thread regarding this matter.

Thank you!