You have at least two options:
1. You can edit the properties of your MS Access database in the design window. Fields can be designated to accept blank values. However, for referential integrity when relating to other tables, this is not an elegant solution.
2. The best solution is to test a field for an undefined value prior to inserting data into the table. Simply, insert a text value "NULL". Here is an example of code I wrote to prevent just such an occurence:
sub validate
{
$valid_data = 1;
@parameters = qw/LASTNAME FIRSTNAME RANK BILLET EMAIL ERO
UNIT DSN RUC NOMEN NSN SERNO COMPANY CONDITION DEFECT SHIP
+MENT
CORRECT COMMENTS/;
@req_param = qw/LASTNAME FIRSTNAME RANK BILLET EMAIL ERO
UNIT DSN RUC NOMEN NSN SERNO COMPANY/;
foreach $response (@parameters)
{
print h3($response, " = ", uc(param($response))), hr;
$CGI_hash{$response} = param($response);
# remove punctuation( ' )which will crash the SQL
$CGI_hash{$response} =~ s/'//g;
# remove hyphens from numbers for consistency
$CGI_hash{"NSN"} =~ s/-//g;
# database demands non-blank values
if ($CGI_hash{$response} eq "")
{
$CGI_hash{$response} = "NULL";
}
$accumulator = $accumulator . uc($CGI_hash{$response}) . "','"
+;
}
&parse_nulls;
chop($accumulator);
chop($accumulator);
$NSN_len = length($CGI_hash{"NSN"});
if ($NSN_len != 13)
{
$valid_data = 0;
}
return;
I hope this helps you.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.