Re: Inserting NULL values does not work
| From: | Andrés Felipe Hernández | Date: | Sun, 03 Feb 2002 00:18:15 +0000 |
| Subject: | Re: Inserting NULL values does not work | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16448@lists.php.net to get a copy of this message | ||
actually, try using $park = "NULL" instead go $park = NULL;
in php NULL is the same that "" which is the same that 0
> ----- Original Message -----
> From: "Rick Emery" <remery@excel.com>
> To: "'Andy'" <news.letters@gmx.de>; <php-db@lists.php.net>
> Sent: Friday, February 01, 2002 7:51 AM
> Subject: RE: [PHP-DB] Inserting NULL values does not work
>
>
> > Your problem is that you've included the value of $park in
single-quotes.
> > Therefore, because it contains NULL, i.e., \0, this is translated to '0'
> in
> > the INSERT statement. You must make your test prior to the INSERT
> statement
> > and use the proper $park value.
> >
> > Or, you can:
> >
> > if ($park == 'false'){
> > $park = NULL;
> > }
> > else{
> > $park = "\"$park\"";
> > };
> >
> > in you INSERT statement change: '$park', to $park,
> >
> > -----Original Message-----
> > From: Andy [mailto:news.letters@gmx.de]
> > Sent: Friday, February 01, 2002 9:43 AM
> > To: php-db@lists.php.net
> > Subject: [PHP-DB] Inserting NULL values does not work
> >
> >
> > Hi guys,
> >
> > I am trying to insert a NULL value into a DB field. The value is not
> always
> > NULL so the statement is given. Unfortunatelly it is inserting 0 instead
> of
> > NULL.
> >
> > How can I get the thing going with NULL???
> >
> > Here is the code I am using:
> >
> > if ($park == 'false'){
> > $park = NULL;
> > }
> >
> > $stmt = "INSERT INTO $T1
> > (
> > belongs_to,
> > name,
> > caption,
> > country,
> > province,
> > city,
> > glacier,
> > park,
> > lake,
> > mountain,
> > beach,
> > comment,
> > keywords,
> > date_taken,
> > date_posted
> > )
> > VALUES
> > (
> > '$user_id',
> > '$picture',
> > '$caption',
> > '$country',
> > '$province',
> > '$city',
> > '$glacier',
> > '$park',
> > '$lake',
> > '$mountain',
> > '$beach',
> > '$comment',
> > '$keyword',
> > '$date_taken',
> > '$date_posted'
> > )";
> >
> > Cheers Andy
> >
> >
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-db-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-db-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>