Example application

Here is a complete example that:
  • Display a menu
  • Display the enter first and last name
  • Add the record to the database
  • Update a record
  • Delete a record
  • Delete all records
  • List records
In this example application we use naming conventions (taken from FuseBox).
dsp??..cfm: display something on the screen
act??..cfm: perform an action, like add, update, delete or list records.
 
First we make the menu file. This file will contain links to all other necessary files in our application.
 
Navigation menu - dsp_menu.cfm
<html>
<head>
<title>Example application</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center"><strong>Navigation menu</strong> <br>
  <br>
  <br>
  <a href="dsp_add_new_record.cfm">Add new record </a><br>
  <a href="dsp_del_all_records.cfm">Delete all records</a> <br>
  <a href="dsp_list_records.cfm">List records [Update | Delete]</a> </div>
</body>
</html>
 

dsp_add_new_record.cfm  (This file will display the input of First Name and Last Name.)

<html>
<head>
<title>Example application</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<div align="center"><strong>Add New Record. </strong></div>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <cfform name="form1" method="post" action="act_add_new_record.cfm">
    <tr>
      <td width="25%">First Name:</td>
      <td width="25%" colspan="2"><cfinput name="first_name" type="text" size="30" maxlength="30" required="yes" message="Please Enter First Name.">
      </td>
    </tr>
    <tr>
      <td width="25%">Last Name:</td>
      <td width="25%" colspan="2"><cfinput name="last_name" type="text" size="30" maxlength="30" required="yes" message="Please Enter Last Name.">
      </td>
    </tr>
    <tr>
      <td width="38%" colspan="2"><input name="add_record" type="submit" id="add_record" value="Add Record"></td>
      <td width="37%"><div align="right">
          <input name="reset" type="reset" id="reset" value="Reset">
        </div></td>
    </tr>
  </cfform>
</table>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>
 
act_add_new_record.cfm
<html>
<head>
<title>Example application</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<cfquery name="add_person" datasource="persondb" username="" password="">
INSERT INTO person (Person_First_Name, Person_Last_Name) VALUES ('#Form.first_name#', '#Form.last_name#')
</cfquery>
<body>
<div align="center"><strong>The record has been successfully added to the database.</strong><br>
  <br>
  <br>
  <a href="dsp_menu.cfm">Back to menu.</a></div>
</body>
</html>
 
dsp_list_records.cfm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
<cfquery name="list_persons" datasource="persondb" username="" password="">
SELECT * FROM person
</cfquery>
<!--- Find Number of records. --->
<cfset number_of_records = list_persons.RecordCount>
</head>
<body>
<div align="center"><strong>List Record(s). </strong></div>
<br>
<cfif number_of_records IS 0>
  <div align="center">There are 0 records in the database. <br>
    <br>
    <a href="dsp_menu.cfm">Back to menu.</a> </div>
  <cfelse>
  <div align="center">There are <cfoutput>#number_of_records#</cfoutput> records in the database. </div>
  <br>
  <br>
  <table width="50%" border="1" align="center" cellpadding="3" cellspacing="0" id="AutoNumber1">
    <tr>
      <th width="33%">First Name</th>
      <th width="33%">Last Name</th>
      <th width="34%" colspan="2">Manage</th>
    </tr>
    <cfloop query = "list_persons" startrow = "1" endrow = "#number_of_records#">
      <cfoutput>
        <tr>
          <td width="33%">#Person_First_Name#</td>
          <td width="33%">#Person_Last_Name#</td>
          <form name="form1" method="post" action="dsp_update_record.cfm?Person_ID=#Person_ID#">
            <td width="17%"><div align="center">
                <input name="update" type="submit" id="update" value="Update">
              </div></td>
          </form>
          <form name="form2" method="post" action="dsp_del_record.cfm?Person_ID=#Person_ID#">
            <td width="17%"><div align="center">
                <input name="delete" type="submit" id="delete" value="Delete">
              </div></td>
          </form>
        </tr>
      </cfoutput>
    </cfloop>
  </table>
  <div align="center"><br>
    <a href="dsp_menu.cfm">Back to menu.</a> </div>
</cfif>
</body>
</html>
 
dsp_update_record.cfm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
</head>
<!--- Find the record. --->
<cfquery name="find_person" datasource="persondb" username="" password="">
SELECT * FROM person WHERE Person_ID = #URL.Person_ID#
</cfquery>
<body>
<div align="center"><strong>Update Record. </strong></div>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <cfform name="form1" method="post" action="act_update_record.cfm?Person_ID=#URL.Person_ID#">
    <tr>
      <td width="25%">First Name:</td>
      <td width="25%" colspan="2"><cfinput name="first_name" type="text" value="#find_person.Person_First_Name#" size="30" maxlength="30" required="yes" message="Please Enter First Name.">
      </td>
    </tr>
    <tr>
      <td width="25%">Last Name:</td>
      <td width="25%" colspan="2"><cfinput name="last_name" type="text" value="#find_person.Person_Last_Name#" size="30" maxlength="30" required="yes" message="Please Enter Last Name.">
      </td>
    </tr>
    <tr>
      <td width="38%" colspan="2"><div align="center">
          <input name="update_record" type="submit" id="update_record" value="Update Record">
        </div></td>
    </tr>
  </cfform>
</table>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>
 
act_update_record.cfm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
</head>
<!--- Update the record. --->
<cfquery name="update_person" datasource="persondb" username="" password="">
UPDATE person SET Person_First_Name = '#Form.first_name#', Person_Last_Name = '#Form.last_name#' WHERE Person_ID = #URL.Person_ID#
</cfquery>
<body>
<div align="center"><strong>The record has been successfully updated </strong> </div>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>
 
dsp_del_record.cfm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
</head>
<!--- Find the record. --->
<cfquery name="find_person" datasource="persondb" username="" password="">
SELECT * FROM person WHERE Person_ID = #URL.Person_ID#
</cfquery>
<body>
<div align="center"><strong>Delete Record. </strong></div>
<br>
First Name: <cfoutput>#find_person.Person_First_Name#</cfoutput><br>
Last Name: <cfoutput>#find_person.Person_Last_Name#</cfoutput> <br>
<br>
<form name="form1" method="post" action="act_del_record.cfm?Person_ID=<cfoutput>#URL.Person_ID#</cfoutput>">
  <div align="center">
    <input name="del_record" type="submit" id="del_record" value="Delete Record">
  </div>
</form>
<br>
<br>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>
 
act_del_record.cfm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
</head>
<!--- Find and delete the record. --->
<cfquery name="del_person" datasource="persondb" username="" password="">
DELETE * FROM person WHERE Person_ID = #URL.Person_ID#
</cfquery>
<body>
<div align="center"><strong>Delete Record. </strong></div>
<div align="center"><br>
  <br>
  <strong>The record has been successfully deleted.</strong> </div>
<br>
<br>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>
 
dsp_del_all_records.cfm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
</head>
<body>
<div align="center"><strong>Delete all records. </strong> </div>
<br>
<br>
<form name="form1" method="post" action="act_del_all_records.cfm">
  <div align="center">
    <input name="del_all_records" type="submit" id="del_all_records" value="Delete all records">
  </div>
</form>
<br>
<br>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>
 

act_del_all_records.cfm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example application</title>
</head>
<!--- Delete all record(s). --->
<cfquery name="del_person" datasource="persondb" username="" password="">
DELETE * FROM person
</cfquery>
<body>
<div align="center"><strong>All records have been deleted. </strong> </div>
<br>
<br>
<div align="center"><br>
  <a href="dsp_menu.cfm">Back to menu.</a> </div>
</body>
</html>

 

 

Advertisement

Internet Million Dollars

No User Comments.

No User Comments, be the first one to write your comments?

ApplayIT is owned by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.