• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

using a cfinput checkbox with a MySQL db issue

Community Beginner ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

Some datatypes for boolean in MySQL:

TINYINT(1)

BIT(1)

ENUM('T','F')

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

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'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation