Copy link to clipboard
Copied
if someone types a url into a form field and it goes into a mysql database. how do i get it to display as an active link on the display page.
aetb846k wrote:
Thanks i changed all those settings without a problem...So basically i want to take a url (e.g. http://www.google.com) thats stored in my data base and display as an active link to the url http://www.google.com
I answered that earlier:
<td><a href="#Recordset1.name#" title="Google homepage">Google</a></td>
This assumes that the value of Recordset1.name is http://www.google.com
Copy link to clipboard
Copied
<!--- Do select query to retrieve URL from database --->
<cfquery name="orgDetails" datasource="myDSN">
select orgID, webURL
from someTBL
where orgID=1234
</cfquery>
<!--- Display link on page --->
<a href="#orgDetails.webURL#" title="Organisation X homepage">Organisation X</a>
Copy link to clipboard
Copied
<p>thanks for your time! I tried to manipulate that code into what i have and it's throwing internal server error. I'd like the name field to be the active link from the url they type in. heres what i have for my output code.
<cfoutput query="Recordset1">
<tr>
<td>#Recordset1.breed# </td>
<td>#Recordset1.name#</td>
<td>#Recordset1.bred# </td>
<td>#Recordset1.due# </td>
</tr></p>
Copy link to clipboard
Copied
Since you want a link, I expected something like
<td><a href="#Recordset1.name#" title="Some title">Some name</a></td>
In any case, the internal server error suggests something else is playing up. Could you show us your query.
Copy link to clipboard
Copied
Thanks for the quick reply!
INSERT INTO litters (breed, name, bred, due)
VALUES (<cfif IsDefined("FORM.breed") AND #FORM.breed# NEQ "">
<cfqueryparam value="#FORM.breed#" cfsqltype="cf_sql_clob" maxlength="50">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.name") AND #FORM.name# NEQ "">
<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_clob" maxlength="50">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.bred") AND #FORM.bred# NEQ "">
<cfqueryparam value="#FORM.bred#" cfsqltype="cf_sql_clob" maxlength="50">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.due") AND #FORM.due# NEQ "">
<cfqueryparam value="#FORM.due#" cfsqltype="cf_sql_clob" maxlength="50">
<cfelse>
''
</cfif>
)
</cfquery>
Copy link to clipboard
Copied
One immediate remark: a CLOB with a maxLength of 50? I would use cf_sql_varchar in place of cf_sql_clob. Unless of course you have a good reason to use CLOB type. For example, are the columns of the table litters of type CLOB?
Also, use the null attribute of the cfqueryparam tag. It is False by default. However, if you set it to True, the query will ignore the value attribute and insert Null into the database table. Something like this
<cfset isBreedNull = true>
<cfset isNameNull = true>
<cfset isBredNull = true>
<cfset isDueNull = true>
<cfif IsDefined("FORM.breed") AND FORM.breed NEQ "">
<cfset isBreedNull = false>
</cfif>
<cfif IsDefined("FORM.name") AND FORM.name NEQ "">
<cfset isNameNull = false>
</cfif>
<cfif IsDefined("FORM.bred") AND FORM.bred NEQ "">
<cfset isBredNull = false>
</cfif>
<cfif IsDefined("FORM.due") AND FORM.due NEQ "">
<cfset isDueNull = false>
</cfif>
INSERT INTO litters (breed, name, bred, due)
VALUES (
<cfqueryparam value="#FORM.breed#" cfsqltype="cf_sql_varchar" maxlength="50" null="#isBreedNull#">
,<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_varchar" maxlength="50" null="#isNameNull#">
,<cfqueryparam value="#FORM.bred#" cfsqltype="cf_sql_varchar" maxlength="50" null="#isBredNull#">
,<cfqueryparam value="#FORM.due#" cfsqltype="cf_sql_varchar" maxlength="50" null="#isDueNull#">
)
Copy link to clipboard
Copied
Thanks i changed all those settings without a problem...So basically i want to take a url (e.g. http://www.google.com) thats stored in my data base and display as an active link to the url http://www.google.com
Copy link to clipboard
Copied
aetb846k wrote:
Thanks i changed all those settings without a problem...So basically i want to take a url (e.g. http://www.google.com) thats stored in my data base and display as an active link to the url http://www.google.com
I answered that earlier:
<td><a href="#Recordset1.name#" title="Google homepage">Google</a></td>
This assumes that the value of Recordset1.name is http://www.google.com
Copy link to clipboard
Copied
Thanks BK! I got it! Yeah!