Solved

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

Posted on 2004-08-12
7
212 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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