I am trying to have three options on a form, the delete is the only one that seems to be giving some problem. The code is posted below, any assitence would be greaty appreciated. <CFIF IsDefined('Delete')> <CFQUERY NAME="DeleteRecord" DATASOURCE="fmd"> DELETE FROM LOGISTICS.FILEMANAGEMENT_DEPARTMENTS WHERE ID = #ID# </CFQUERY> </CFIF> <cfquery name="getdept" datasource="fmd"> SELECT * FROM LOGISTICS.FILEMANAGEMENT_DEPARTMENTS ORDER BY dep_code </cfquery> <html> <head> <title> File Management Department Update</title> </head> <body> <center> <h3> Departments</h3> <table border="3" cellpadding="5" cellspacing="0" bgcolor="0042ff"> <form action="updateform.cfm" method="post"> <tr> <td rowspan="3"> <select name="ID" size="5"> <cfoutput query="getdept"> <option value="#ID#" <cfif getdept.currentrow EQ 1> SELECTED </cfif>>#department_name#</option> </cfoutput> </select> </td> <td> <form action="updateform.cfm" method="post"> <input type="submit" name="Update2" value="Update Record"> </td> </form> </tr> <tr> <form action="UpdateMenu_Form.cfm" method="post"> <td><input type="submit" name="Delete" value="Delete Record" onClick="return confirm('Are you sure you want to delete this record?')"> </td> </tr> </form> <tr> <form action="insertForm.cfm" method="post"> <td><input type="submit" name="Insert" value="Add a new record"></td> </form> </tr> </table> </center> </body> </html>
Hi balleyne, Thanks for posting the code. One other bit of information needed is a description of the problem. In other words something like "currently my code is doing (this) ... but what I would like it to do is (that)"
Oh, Sorry about that cfStarlight, what is NOT happening is that when the "Delete Record" button is clicked, it throws an error as if the page (UpdateMenu_Form.cfm), which calls the 'Delete' function does not exist. BTW, the name I saved this page as is UpdateMenu_Form.cfm. What I would like to happen is that the highlighted record is deleted when the button is clicked. The interface is supposed to seek confirmation from the user before performing the delete.
One problem is that the "ID" value will not be passed to your action page, since the select list (and each of the buttons) are all defined in a separate <form>. Try 1) putting them all in the _same_ form 2) giving the buttons the same _name_ 3) and posting the form to a single action page. Then run different code, depending on the button value YourActionPage.cfm <CFIF IsDefined('form.actionType')> <cfif form.actionType is "Delete Record"> <!--- use cfqueryparam for all queries! ---> <CFQUERY NAME="DeleteRecord" DATASOURCE="fmd"> DELETE FROM LOGISTICS.FILEMANAGEMENT_DEPARTMENTS WHERE ID = #ID# </CFQUERY> <cfelseif form.actionType is "Update Record"> <!--- your update code here ---> <cfelseif form.actionType is "Add a new record"> <!--- your insert code here ---> </cfif> </CFIF> YourFormPage.cfm .... other code ... <h3> Departments</h3> <table border="3" cellpadding="5" cellspacing="0" bgcolor="0042ff"> <form action="Action.cfm" method="post"> <tr> <td rowspan="3"> <select name="ID" size="5"> <!--- your option tags here ---> </select> </td> <td> <input type="submit" name="actionType" value="Update Record"> </td> </tr> <tr> <td><input type="submit" name="actionType" value="Delete Record" onClick="return confirm('Are you sure you want to delete this record?')"></td> </tr> <tr> <td><input type="submit" name="actionType" value="Add a new record"></td> </form> </tr> </table> Code (markup):
Thanks, cfStarlight, I took your advice and created one page with all functions and it works perfectly!!
I am glad you got it working. BTW, I did not mention it before but you should use cfqueryparam rather than using form and url values directly in queries. The reasons are performance benefits and also some protection against sql injection in your application. You can look up the details in the online documentation, but the general syntax is: WHERE ColumnName = <cfqueryparam value="#yourVariable#" cfsqltype="cf_sql_integer"> The "cfsqltype" value will vary based on the data type of the column you are working with. The cfsqltype values correspond to your basic database data types (varchar, integer, ...) but start with "cf_sql" (cf_sql_varchar, cf_sql_integer, ...) http://livedocs.adobe.com/coldfusion/8/Tags_p-q_18.html