Home arrow MySQL arrow Page 4 - Building a Simple ColdFusion Content Management System with MySQL

Add/Modify Form - MySQL

This tutorial lays out the basics for creating a content management system in ColdFusion and MySQL. The System leverages hierarchical data to automatically build breadcrumb lists, a side navigation menu, as well as a site map. The goal of this tutorial is to provide a framework upon which to build a content management system that is easy to customize and maintain, leaving the web author more time to create content than maintain code.

TABLE OF CONTENTS:
  1. Building a Simple ColdFusion Content Management System with MySQL
  2. Starting With MySQL
  3. The Page and how to Update/Modify and Delete
  4. Add/Modify Form
  5. Action
  6. Breadcrumb List
  7. Side Menu
  8. Site Map
By: Charles Kaufmann
Rating: starstarstarstarstar / 48
August 11, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

We are now going to look at the add and modify process of this application. When you click on either the Modify or Add link it will take you to the first part of the CFIF statement. I am just going to state once for the record that these forms were intentionally left very plain. I was going for function, you can make it look nice when you integrate it into your site.

Here is the code:

1  <cfif isdefined("url.mod")>
           <cfset url.id = #url.mod#>
   <cfelse>
           <cfset url.id = 0>
   </cfif>
2  <cfquery name="getpage" datasource="#variables.data#">
3     Select *
4     From tblpages
5     where id = #url.id# and status = 'A'
6  </cfquery>
7  <form action="page.cfm" method="post" name="form1">
8  <cfoutput>
9  Title:<br />
10 <input type="Text" name="title" value="#getpage.title#" /><br />
11
12 Body:<br />
13 <textarea name="body" cols="40" rows="10">#getpage.body#</textarea>
14 <br />
15
16 <cfif isdefined("url.add")>
17   <input type="Hidden" name="id" value="#url.add#" />
18   <input type="Submit" name="Add" Value="Add" />
19 <cfelse>
20   <input type="Hidden" name="id" value="#url.mod#" />
21   <input type="Submit" name="Modify" value="Modify" />
22 </cfif>
23 </cfoutput>
24 </form>
 

Now I will walk through the above code. The first CFIF statement (line 1) sets a url.id to either 0 for a new record, or a value that was passed in the "url.mod". What this does for you is if you are modifying a page, it will show the information in the form, if you are adding a page the form will be blank.

The CFQUERY queries out the record if you are modifying. Set the form's ACTION to the same page you are working on. Lines 8 through 14 place the form fields on the page and populate them with values if you are modifying the record. Lines 16 through 23 test to see what you are trying to and sends you to the appropriate action. If you are trying to modify an existing document the submit button is named Modify with a value of Modify. If you are trying to add a new document then the submit button is named Add with a value of Add. That way you can put the appropriate action in the section of the page's CFIF statements. All you have to do is see if the form variables are ISDEFINED.



 
 
>>> More MySQL Articles          >>> More By Charles Kaufmann
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: