Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199807

Re: [PHP3] How do I insert NULL??? From: Richard Lynch (lynch <email protected>)
Date: 07/31/98

I could be wrong: I frequently am...

But I think y'all are over-engineering.

Unless you've got some fancy way for the user to indicate that they really do want an empty string for a field, and thus shouldn't be asked to fill it in later, just put the empty string in, and when you want to find "blanks", search for the empty string.

Convoluting your code to stick a NULL in instead of "" is silly, unless you actually want them to be distinct.

All you *seem* to care about from your description is that "blank" fields (NULL *OR* '') should later be reviewed and filled in.

It's going to be way easier to do *JUST* this:

<?php
  error_reporting(7);
  $query = "insert into table (f1, f2, ... fN) values('$v1', '$v2', ... '$vN')";
  error_reporting(15);
  .
  .
  .
  $query = "select distinct * from table where f1 is null or f1 = ''... ";
  
  /* Are $E_ERROR + $E_WARNING + $E_PARSE + $E_WARNING defined?
     If so, use those instead of 7 and 15... */
?>

Actually, if the ONLY way for data to get into your table is from your webpage, you can take out all the 'fieldI is null or' stuff.

So:

Take out that crap about if (!isset($field){ $field='';}
Don't put in complex stuff to force NULL into fields where a blank is just as easy to find, and way easier to insert.

Use the above instead, and over-ride the default warning-level for that one line where you know what you are doing, and you really don't want to be warned about undefined variables.

Disclaimer: You may *NEED* to distinguish between '' and NULL, and allow users to notate fields that are *SUPPOSED* to be blank, ''... but I doubt it.

-- 
--
-- "TANSTAAFL" Rich lynch <email protected>

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3