Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,372 Programmers for FREE! Ask your question and get quick answers from experts. There are 967 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



delete entries

 
Reply to this topicStart new topic

delete entries

aylin0315
post 21 Oct, 2007 - 06:41 PM
Post #1


New D.I.C Head

*
Joined: 16 Oct, 2007
Posts: 4


My Contributions


i am doing a sample program of add, edit and delete but i cant view the entries that i wanted to delete, as well i cant also delete the data on my database using the form.
here's my code.. hope anyone can help me with this.. thanks..

<cfquery datasource="aileen" name="getDetails">
SELECT * from sample
</cfquery>


<html>

<cfoutput>
<table>
<tr bgcolor="blue" bordercolor="black">View Details
<td>ID</td>
<td>FirstName</td>
<td>MiddleName</td>
<td>LastName</td>
<td>Address</td>
<td>ContactNo</td>
<td>School</td>
</tr>
<cfloop query="getDetails">
<tr><cfform action="view2.cfm" method="get">
<td><cfinput value="#getDetails.id#" name="id" size="5"/></td>
<td><cfinput value="#getDetails.last_name#" name="last_name" size="10"/></td>
<td><cfinput value="#getDetails.middle_name#" name="middle_name" size="10"/></td>
<td><cfinput value="#getDetails.last_name#" name="last_name" size="10"/></td>
<td><cfinput value="#getDetails.address#" name="address" size="10"/></td>
<td><cfinput value="#getDetails.contact_number#" name="contact_number" size="10"/></td>
<td><cfinput value="#getDetails.school#" name="school" size="10"/></td>
<td><input name="btnEdit" type="submit" id="btnEdit" value="edit" onClick="http://localhost:8500/update.cfm?edit=edit" /></td>
<td><INPUT type="submit" name="btnDelete" value="DELETE!" id="btnDelete" onClick="http://localhost:8500/update.cfm?delete=delete"/></td>
<cfif isdefined ('form.id')>
<cfquery datasource="aileen" name="deleteDetails">
DELETE id from sample
where id = #form.id#

</cfquery>
</cfif>

</cfform>
</tr>
</cfloop>
</table>
</cfoutput>
</html>
User is offlineProfile CardPM

Go to the top of the page


skyhawk133
post 21 Oct, 2007 - 07:07 PM
Post #2


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,482



Thanked 34 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


Are you getting an error? Or is it just not making it to the DELETE query?

Also, please post your code using code tags like this: code.gif
User is offlineProfile CardPM

Go to the top of the page

aylin0315
post 21 Oct, 2007 - 11:04 PM
Post #3


New D.I.C Head

*
Joined: 16 Oct, 2007
Posts: 4


My Contributions


here's my new code. i dont know how to add a "delete" options all i have is edit.. thanks

CODE

<cfif IsDefined("URL.From")>
<cfif #URL.From# IS "DoEdit">
    <cfquery name="Update" datasource="aileen">
            UPDATE sample
            SET id = '#form.id#',
                first_name='#form.first_name#',
                middle_name='#form.middle_name#',
                last_name='#form.last_name#',
                address='#form.address#',
                contact_number='#form.contact_number#',
                school='#form.school#'
            WHERE id = '#URL.id#'
    </cfquery>
</cfif>
</cfif>

<cfif isdefined ("URL.FROM")>
<cfif #URL.FROM# is "DoDelete">
    <cfquery name="Delete" datasource="aileen">
        Delete id from sample
        where id = #URL.id#
    </cfquery>
</cfif>
</cfif>


<cfquery name="GetData" datasource="aileen">
    SELECT *
    FROM sample
    ORDER BY id  
</cfquery>

<html>
    <head>
        <title>View Entries</title>
    </head>
<body>
        <p>Enries are as follows:
<table>
                <tr>
                <th>ID</th>
                <th>first_name</th>
                <th>middle_name</th>
                <th>last_name</th>
                <th>address</th>
                <th>contact_number</th>
                <th>school</th>
                <th></th>
                </tr>
                    <CFIF IsDefined("URL.From")>
                    <CFIF #URL.From# IS "DoEdit">
                    <CFOUTPUT QUERY="GetData">
                <tr>
                <td>#id#</td>
                <td>#first_name#</td>
                <td>#middle_name#</td>
                <td>#last_name#</td>
                <td>#address#</td>
                <td>#contact_number#</td>
                <td>#school#</td>
                <td>
                    <form action="edit.cfm?From=Edit&ID=#ID#" method="post">
                    <input type="submit" value="Edit">
                    </form></td>
                
                </tr>
</CFOUTPUT>

<CFELSE>

<CFLOOP QUERY="GetData">

<CFIF #URL.ID# IS #GetData.ID#>

<CFOUTPUT>

<form action="edit.cfm?From=DoEdit&ID=#ID#" method="post">

<tr>
<td><input type="text" name="id" size="4" value="#id#"></td>
<td><input type="text" name="first_name" size="20" value="#first_name#"></td>
<td><input type="text" name="middle_name" size="40" value="#middle_name#"></td>
<td><input type="text" name="last_name" size="20" value="#last_name#"></td>
<td><input type="text" name="address" size="40" value="#address#"></td>
<td><input type="text" name="contact_number" size="20" value="#contact_number#"></td>
<td><input type="text" name="school" size="40" value="#school#"></td>
</tr>
</CFOUTPUT>
<CFELSE>

<CFOUTPUT>
<tr>
<td>#id#</td>
<td>#first_name#</td>
<td>#middle_name#</td>
<td>#last_name#</td>
<td>#address#</td>
<td>#contact_number#</td>
<td>#school#</td>
<td>
</td>
</tr>
</CFOUTPUT>

</CFIF>

</CFLOOP>

</CFIF>



<CFELSE>

<CFOUTPUT QUERY="GetData">
<tr>
<td>#id#</td>
<td>#first_name#</td>
<td>#middle_name#</td>
<td>#last_name#</td>
<td>#address#</td>
<td>#contact_number#</td>
<td>#school#</td>


<td>
<form action="edit.cfm?From=Edit&ID=#ID#" method="post">
<input type="submit" value="Edit">
</form></td>

<td>
<cfform action="edit.cfm?From=Delete&ID=#id#" method="post">
<cfinput name="delete" type="submit" value="Delete" message="are you sure u want to delete?">
</cfform></td>

</tr>
</CFOUTPUT>

</CFIF>



<CFIF IsDefined("URL.From")>
<CFIF #URL.From# IS "Edit">

<tr>
<td colspan="3">
<CFOUTPUT>
<input type="hidden" name="ID" value="#URL.ID#">
</CFOUTPUT>
<input type="submit" value="Update">
</form></td>
</tr>

</CFIF>
</CFIF>

    </table>

</body>

</html>
User is offlineProfile CardPM

Go to the top of the page

supersssweety
post 22 Oct, 2007 - 07:30 AM
Post #4


D.I.C Regular

Group Icon
Joined: 16 Mar, 2007
Posts: 292



Dream Kudos: 125
My Contributions


You are kind of all over the place in your code...some comments would be nice, I don't really have the time to walk through all that code, it seems there may be a more efficient way that this could be done. I am one to have to see things visually too. It would help if you could comment your code or set up a testing page with the same functionality.

From what I can gather, it seems you would just do the delete the same way you would do the edit, it also seems as if you are asking for an SQL delete statement. It looks like you have some delete functionality in there but no actual query to perform the delete.

Here is some help for that

As far as the design goes...the way I would do it is this:

Have a blank form that the user fills out
on submit, it will update the database and then display the information as text
under the text it would have two link:
Delete - which will run the delete query
Edit - which would take you to a page just like the form, only the information submitted before will be in there, then when they hit submit again, it would update...

Need more information
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 11:33PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month