Solved

Trying a db insert but fails due to nothing being passed in one of my form fields...

Posted on 2004-08-12
7
208 Views
Last Modified: 2013-12-24
Hi,

I am trying to do a simple database insert, however, I seem to have a problem because the column in my table is set to

stateProvinceCode nchar(3)  and does not accept nulls

I have a drop down box on my page like so

<select name="stateProvince" id="stateProvince">
          <option value="">Select One</option>
          <option value="CA">California</option
 </select>

I want to be able to submit my form without having to choose a State/Province.  If I choose nothing it passes "" which seems to cause a problem, because if I choose a state, I do not get any error.

If my column is set to not accept nulls, and has a datatype of nchar(3) how can I get around this?

The stateProvinceCode column is a FK from another table, a table called StateProvince

Should be simple to fix, but I can't seem to get it.

Any help appreciated.

-WS

0
Comment
Question by:Westside2004
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Expert Comment

by:zakaz
ID: 11781894
I would use a <cfparam> tag on the receiving page with default of Null. This at least fills the table

<cfparam name="stateProvince" default="null">
0
 
LVL 11

Accepted Solution

by:
hart earned 125 total points
ID: 11781959
FK can also be null....
why don't you just change the table not null to allow nulls....

else....

or in StateProvince create a value with 0 as a value and pass that in the db...
then you won't have to change anything...

what i mean is <option value="0">Select One</option>

and db insert 0...
also you will have a record with 0 in stateprovince table...

Regards
Hart

0
 
LVL 11

Expert Comment

by:hart
ID: 11782030
zakaz : you won't be able to put "NULL" value into the db as the field is a FK to stateprovince...

Regards
Hart
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Expert Comment

by:zakaz
ID: 11782558
True Hart anything,

i would do as you said change the db myself or stick in "None Chosen" as please choose value in select
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 11783344
hart has the the solution, but i would use XX inplace of 0, then you are consistent in the format

<select name="stateProvince" id="stateProvince">
          <option value="XX">Select One</option>
          <option value="CA">California</option
             ....
 </select>
0
 
LVL 1

Author Comment

by:Westside2004
ID: 11785340
Hi,

Yes, I just added a value in the StateProvince table with XX

And it worked..

Thanks

West
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 11785465
partly my solution....

and nothing for me :-{

;-)

glad you got it working, in your provisnce state table add

XX Not Listed

as the code and long text
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XML problem with Internet Explorer 7 30
Website Hosting for Best Worldwide Response Times 6 127
Need help with htaccess file 10 52
IIS 8.5 2 44
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now