Re: Inserting NULL values does not work
| From: | Oliver Cronk | Date: | Fri, 01 Feb 2002 17:46:09 +0000 |
| Subject: | Re: Inserting NULL values does not work | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16424@lists.php.net to get a copy of this message | ||
right ok yes I see, but surely thats
$querystr = "INSERT INTO mytable (name) VALUES(\"O'leary\") " otherwise
the
query string gets truncated by PHP at the values point???
My point simply is that he IS using single quotes (see below) and would
therefore suffer from this problem (hence the reason for suggesting such
additional functionality + consideration to validation of input).
> > $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'
> > )";
But I don't want to piss you off and as you will undoubtable have more mysql
experience than me so please don't take this as some kind of points scoring
exercise / competition - I was just suggesting some additional features he
might want to consider at the same point.
Ollie
"Rick Emery" <remery@excel.com> wrote in message
news:<EAA093B474ABD311A71E00508B5FE08305C2D090@adntex03.us.excel.com>...
> It won't fail if it is enclosed in double-quotes. That is:
>
> INSERT INTO mytable (name) VALUES("O'leary")
>
> is OK.
>
> -----Original Message-----
> From: Oliver Cronk [mailto:ocronk@essex.ac.uk]
> Sent: Friday, February 01, 2002 10:41 AM
> To: Rick Emery; oliver@cronky.net; Php-Db ML
> Subject: RE: [PHP-DB] Inserting NULL values does not work
>
>
> I know its not failing on YOUR example but if there is a single quote in
the
> data eg someones name is O'leary then the SQL will fail surely?
>
> Ollie
>
> -----Original Message-----
> From: Rick Emery [mailto:remery@excel.com]
> Sent: 01 February 2002 16:13
> To: 'oliver@cronky.net'; Php-Db ML
> Subject: RE: [PHP-DB] Inserting NULL values does not work
>
>
> It's not failing on the single-quotes. MYSQL can use single-quotes.
>
> -----Original Message-----
> From: Oliver Cronk [mailto:ocronk@essex.ac.uk]
> Sent: Friday, February 01, 2002 10:01 AM
> To: Php-Db ML; remery@excel.com
> Subject: Re: [PHP-DB] Inserting NULL values does not work
>
>
> Why not make it a function which also checks and replaces for characters
SQL
> fails on eg if ' replace with '' in strings etc, and does any sanity /
> validation checks at the same time?
>
> Ollie
>
> "Rick Emery" <remery@excel.com> wrote in message
>
> news:<EAA093B474ABD311A71E00508B5FE08305C2D089@adntex03.us.excel.com>...
> > 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
>