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
Copy link to clipboard
Copied
Do you get an sql error when you run that code? If so, what does it say?
Copy link to clipboard
Copied
Which is the data type of "isAdminstrator" column in your MySQL table?
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.
Copy link to clipboard
Copied
Some datatypes for boolean in MySQL:
TINYINT(1)
BIT(1)
ENUM('T','F')
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
Unknown column 'adminUser.isAdminstrator' in 'field list'
Copy link to clipboard
Copied
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.