Skip to main content
Known Participant
December 8, 2011
Question

using a cfinput checkbox with a MySQL db issue

  • December 8, 2011
  • 3 replies
  • 1476 views

Hello;

I'm trying to use a checkbox to enable a person as a user in an admin section for a site. I am posting the code I am using, it works in SQL and access, but I am unsure of what the setting is for a field using yes/no - on/off type of input. Can anyone help me with what the setting is for mySQL?

My code:

<form>

<cfinput type="checkbox" value="admin" name="admin">

</form>

<!--- insert statement --->

<cfif not IsDefined("FORM.admin")>

<cfset IsAdmin= 0>

<cfelse>

<cfset IsAdmin= 1>

</cfif>

<cfquery datasource="#APPLICATION.dataSource#" dbtype="ODBC">

INSERT INTO adminUser

(Fname, Lname, userName, password, email, _phone, isAdminstrator)

VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.Fname#">,

<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.Lname#">,

<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.userName#">,

<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.txtPassword#">,

<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.email#">,

<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.phone#">,

<cfqueryparam value="#IsAdmin#" CFSQLType="CF_SQL_INTEGER">)

</cfquery>

I know it's how i have this cell set in my DB. Can anyone help me out?

Thanks

This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
December 8, 2011

Some datatypes for boolean in MySQL:

TINYINT(1)

BIT(1)

ENUM('T','F')

Known Participant
December 8, 2011

I had it set as bit also with a Length/Values of 1 and no atrtributes
when I try and make the attributes binary, it throws an error.

This is my error in CF

Error Executing Database Query

Unknown column 'adminUser.isAdminstrator' in 'field list'

BKBK
Community Expert
Community Expert
December 8, 2011

cfsetNewbie wrote:

I had it set as bit also with a Length/Values of 1 and no atrtributes
when I try and make the attributes binary, it throws an error.

This is my error in CF

Error Executing Database Query

Unknown column 'adminUser.isAdminstrator' in 'field list'

That simply seems to be telling you there is no column called isAdminstrator. You apparently omitted the letter i from isAdministrator.

Inspiring
December 8, 2011

Which is the data type of "isAdminstrator" column in your MySQL table?

Known Participant
December 8, 2011

I do get an error is says the field is undefined. I have the cell set as tinyint with no collation, Null=no, no attributes and no default, it should be default 0, I'll change that. But it's trying to grab a user and it's set as 1.

Inspiring
December 8, 2011

Do you get an sql error when you run that code?  If so, what does it say?