我正在尝试制作一个访问 MySQL 数据库的表单。但这一切对我来说都是新鲜的。我想我可能试图超越我对此的基本理解。这是我的问题。
我有一个表格。在这种形式中,我与数据库建立了连接,并且能够发布到数据库。我想做的是有一个带有“tile 1”、“tile 2”、“tile 3”的选项字段。对于每个“图块”,我希望将其余字段保存在该图块 ID 下。从选项字段中选择磁贴时,我还希望能够提取该磁贴信息。
这是我当前的代码。请记住,我对所有这些都是新手。谢谢。
形式:
<cfform method="post" name="TileAdAdmin" action="index.cfm">
<cfoutput>
<table width="500px">
<tr>
<td height="159"><label class="labelStyle">Tile Ads</label></td>
<td>
Tile Number:<select name="TAID" id="TAID">
<option value="0">None</option>
<option value="1">Tile 1</option>
<option value="2">Tile 2</option>
<option value="3">Tile 3</option>
</select><br /><br />
Headline:
<input name="TAHL" type="text" id="TAHL" title="TAHL" value="#variables.ta.TAHL#" maxlength="30" />
<br />
Image Name:
<input name="TAImage" type="text" id="TAImage" title="TAImage" value="#variables.ta.TAImage#" maxlength="30" />
<br />
Discription:
<textarea name="TADiscription" cols="30" rows="6" id="TADiscription" title="VimeoID">#variables.ta.TADiscription#</textarea> <br />
</td>
</tr>
</table><br />
<input type="hidden" value="#variables.controller#" name="controller">
<input type="hidden" value="#variables.action#" name="action">
<input type="Submit" value="Submit" name="Submit" class="formInput">
</cfoutput>
</cfform>
道代码:
<cfcomponent name="TADAO" displayname="" hint="" output="false">
<cffunction name="read" access="public" returntype="Void" output="false" hint="CRUD method">
<cfargument name="ta" type="ta" required="yes" />
<cfset var qRead = 0 />
<cfquery name="qRead" datasource="#Application.dbsource#" >
SELECT
TAID,
TAHL,
TAIMAGE,
TADISCRIPTION
FROM
T026_TILE_ADS
</cfquery>
<cfif qRead.RecordCount>
<cfset arguments.ta.setTAID(qread.TAID) />
<cfset arguments.ta.setTAHL(qread.TAHL) />
<cfset arguments.ta.setTAImage(qread.TAIMAGE) />
<cfset arguments.ta.setTADiscription(qread.TADISCRIPTION) />
<cfelse>
<cfthrow type="emptyRecordset" errorcode="TADAO.read.emptyRecordset" message="Unable to locate the TILE_AD data record." />
</cfif>
</cffunction>
<cffunction name="update" access="public" returntype="Void" output="false" hint="CRUD method">
<cfargument name="TA" type="TA" required="yes" />
<cfquery name="qUpdate" datasource="#Application.dbsource#">
UPDATE
T026_TILE_ADS
SET
TAID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#arguments.ta.getTAID()#" />,
TAHL = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.ta.getTAHL()#" />,
TAIMAGE = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.ta.getTAImage()#" />,
TADISCRIPTION = <cfqueryparam cfsqltype="cf_sql_text" value="#arguments.ta.getTADiscription()#" />
</cfquery>
</cffunction>
</cfcomponent>
组件代码:
<cfcomponent displayname="ta" hint="" output="false">
<cfproperty name="TAID" displayname="" type="numeric" />
<cfproperty name="TAHL" displayname="" type="string" />
<cfproperty name="TAImage" displayname="" type="string" />
<cfproperty name="TADiscription" displayname="" type="string" />
<cffunction name="init" access="public" returnType="TA" output="false" hint="">
<cfset this.TAID = 0 />
<cfset this.TAHL = "headline" />
<cfset this.TAImage = "IMAGE" />
<cfset this.TADiscription = "Discription" />
<cfreturn this />
</cffunction>
<cffunction name="getTAID" access="public" output="false" returntype="numeric">
<cfreturn this.TAID />
</cffunction>
<cffunction name="setTAID" access="public" output="false" returntype="void">
<cfargument name="TAID" type="numeric" required="true" />
<cfset this.TAID = arguments.TAID />
<cfreturn />
</cffunction>
<cffunction name="getTAHL" access="public" output="false" returntype="string">
<cfreturn this.TAHL />
</cffunction>
<cffunction name="setTAHL" access="public" output="false" returntype="void">
<cfargument name="TAHL" type="string" required="true" />
<cfset this.TAHL = arguments.TAHL />
<cfreturn />
</cffunction>
<cffunction name="getTAImage" access="public" output="false" returntype="string">
<cfreturn this.TAImage />
</cffunction>
<cffunction name="setTAImage" access="public" output="false" returntype="void">
<cfargument name="TAImage" type="string" required="true" />
<cfset this.TAImage = arguments.TAImage />
<cfreturn />
</cffunction>
<cffunction name="getTADiscription" access="public" output="false" returntype="string">
<cfreturn this.TADiscription />
</cffunction>
<cffunction name="setTADiscription" access="public" output="false" returntype="void">
<cfargument name="TADiscription" type="string" required="true" />
<cfset this.TADiscription = arguments.TADiscription />
<cfreturn />
</cffunction>
<cffunction name="dump" access="public" output="true" returntype="void">
<cfoutput>
Tile: #this.TAID# <br />
Headline: #this.TAHL# <br />
Image: #this.TAImage# <br />
Description: #this.TADiscription# <br />
</cfoutput>
</cffunction>