Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2008, 10:52 AM
Registered User
 
Join Date: May 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display Deleted record name

Hi

I have created a asp page that allows me to delete data from a webpage but it only displays the ID of the record that i have deleted how can i get it to show the name of the person that i have deleted (name in field "firstname")

Here is what i have got so far

This is the page that shows the users do that i can click on the delete button to delete them

Code:
<% 
    pStr = "private, no-cache, must-revalidate" 
    Response.ExpiresAbsolute = #2000-01-01# 
    Response.AddHeader "pragma", "no-cache" 
    Response.AddHeader "cache-control", pStr 
%>

<head>
    <style>
    td { font-size : 8pt; font-family : Verdana, Arial; text-decoration : none; }
    body { font-size : 8pt; font-family : Verdana, Arial; text-decoration : none; }
    </style>
</head>

<body>
<p align="center"><b>All Records Entered :</b></p>
<table align="center" border=0 cellpadding=3 cellspacing=3 cols=2 width=400>
<%
   ' Declaring variables
   Dim rs, data_source, no
   no = 0
   data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
            Server.MapPath("employee.mdb")

   ' Creating Recordset Object and opening the database
   Set rs = Server.CreateObject("ADODB.Recordset")
   rs.Open "employees", data_source
   ' Looping through the records to show all of them
   While Not rs.EOF %>
<form action="del.asp" method="post">
<tr>
    <td align="right" height=10 valign="top">First Name :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("firstname") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">Sur Name :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("surname") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">Department :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("Department") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">Site :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("Site") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">Ext :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("EXT") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">DDI :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("DDI") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">Mobile :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("Mobile") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top">Email :</td>
    <td align="left" height=10 valign="top" width=250><%=rs("Email") %></td>
</tr>
<tr>
    <td align="right" height=10 valign="top"><input type="hidden" name="id" value="<%=rs("id")%>"></td>
    <td align="left" height=10 valign="top" width=250><input type="submit" value="Delete" style="height: 25px; width: 100px"></td>
</tr>
</form>
<tr>
    <td align="right" height=10 valign="top"><input type="hidden" name="first_name" value="<%=rs("firstname")%>"></td>
</tr>

  <%
   no = no + 1
   rs.MoveNext
   Wend
   ' Done. Now close the Recordset
   rs.Close
   Set rs = Nothing
 %>
 <tr>
    <td align="right" height=10 valign="top"><b>Total Records Found</b> :</td>
    <td align="left" height=10 valign="top" width=250><%= no %></td>
</tr>
 </table>
</body>
</html>
And this is the Page that it goes to to delete the user from the database

Code:
<html>
<head>
<style>
    body { font-size : 8pt; font-family : Verdana, Arial; }
</style>
</head>

<body>
<%
IF Len(Request.Form("id")) Then
' Declaring variables
Dim form_id, first_name, data_source, sql_delete, con
 form_id = CInt(Request.Form("id"))
 'first_name = (Request.Form("firstname"))
 data_source =  "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
                 Server.MapPath("employee.mdb")
 sql_delete = "delete from employees where id = " & form_id
 
 Set con = Server.CreateObject("ADODB.Connection")
 con.Open data_source
 con.Execute sql_delete
 con.Close
 Set con = Nothing
response.write "<script>alert('Record No. : " & first_name & " was successfully deleted from the database.');history.back(-1,0);</script>"
 
 Else
 Response.Redirect "showall.asp"
 End If%>

</body>
</html>
i want this to show the name of the person that has been deleted
Code:
response.write "<script>alert('Record No. : " & first_name & " was successfully deleted from the database.');history.back(-1,0);</script>"
 
Old May 19th, 2008, 12:35 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Just put the first name value in a hidden tag like you're doing with the ID.

 
Old May 19th, 2008, 12:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:Just put the first name value in a hidden tag like you're doing with the ID.
He's already doing that. However, not entirely correct as the field is defined *outside* the form:

</form><tr>
    <td align="right" height=10 valign="top"><input type="hidden" name="first_name" value="<%=rs("firstname")%>"></td>
</tr>

Move the field into the <form /> and you can read it on the Delete page:

<tr>
    <td align="right" height=10 valign="top"><input type="hidden" name="first_name" value="<%=rs("firstname")%>"></td>
</tr>
</form>

BTW: the code is open to what is known as "SQL injection", possible leading to loss of a data, a hacked server, and viruses for your clients (recently witnessed that very closely). You may want to Google for "SQL injection" to learn what counter measures to take.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old May 19th, 2008, 01:49 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

OK. That's why I didn't see the first_name hidden tag. Yeah, and the other reason is... Good eye mate.

 
Old May 20th, 2008, 08:04 AM
Registered User
 
Join Date: May 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi i have edited the other bit of code
what do i need to change in this bit of code to get it working i doesnt actualy tell me who has been deleted yet
Here is the code

Code:
<html>
<head>
<style>
    body { font-size : 8pt; font-family : Verdana, Arial; }
</style>
</head>

<body>
<%
IF Len(Request.Form("id")) Then
' Declaring variables
Dim form_id, first_name, data_source, sql_delete, con
 form_id = CInt(Request.Form("id"))
 first_name = (Request.Form("firstname"))
 data_source =  "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
                 Server.MapPath("employee.mdb")
 sql_delete = "delete from employees where id = " & form_id
 
 Set con = Server.CreateObject("ADODB.Connection")
 con.Open data_source
 con.Execute sql_delete
 con.Close
 Set con = Nothing
response.write "<script>alert('Record No. : " & first_name & " was successfully deleted from the database.');history.back(-1,0);</script>"
 
 Else
 Response.Redirect "showall.asp"
 End If%>

</body>
</html>

i am new to ASP so not to sure how to do much
 
Old May 20th, 2008, 08:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This should be easy to find out yourself, isn't? Just a matter of following the red wire?

First, look at the hidden form fuield:

<input type="hidden" name="first_name" value="<%=rs("firstname")%>">

Then look at your code that tries to find the user name:

'first_name = (Request.Form("firstname"))

First, it's commented out so it's not in effect. Secondly, there seems to be a mismatch in the name of the field....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old May 20th, 2008, 09:04 AM
Registered User
 
Join Date: May 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 This should be easy to find out yourself, isn't? Just a matter of following the red wire?

First, look at the hidden form fuield:

<input type="hidden" name="first_name" value="<%=rs("firstname")%>">

Then look at your code that tries to find the user name:

'first_name = (Request.Form("firstname"))

First, it's commented out so it's not in effect. Secondly, there seems to be a mismatch in the name of the field....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
I have changed the code so that it is no longer commented out as you can see in the reply above what else do i need to change ?

James

 
Old May 20th, 2008, 10:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Isn't that clear in my reply? Don't you see the mismatch in names:

<input type="hidden" name="first_name" value="<%=rs("firstname")%>">
first_name = (Request.Form("firstname"))

The field is called first_name yet you try to access it as firstname in the delete page.

P.S. No need to quote the entire reply when you make a post here. It clutters up the post and adds little value...

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
record display Ashleek007 Beginning PHP 1 July 22nd, 2005 01:40 PM
Record Deleted Error Message VB6 akash BOOK: Expert One-on-One Access Application Development 0 March 8th, 2005 06:53 AM
can't display record from table. jenjenyan Access ASP 3 June 5th, 2004 12:36 AM
# DELETED Record Access RT Jim6560 Access 0 March 21st, 2004 01:06 PM
Display a single record.. PLEASE HELP TnTandyO Classic ASP Databases 26 September 9th, 2003 10:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.