Re: Inserting NULL Integer Values
| From: | Ben Litton | Date: | Tue, 18 Oct 2005 18:29:25 +0000 |
| Subject: | Re: Inserting NULL Integer Values | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-224290@lists.php.net to get a copy of this message | ||
Yes, but NULL is a special thing to MySQL. If you don't quote 'NULL' it just means 'empty' to mySQL. If your database schema allows NULLS (it's optional), your insert will go through.
On Tue, 18 Oct 2005 13:10:32 -0400, "Shaun" <shaunthornburgh@hotmail.com> wrote:
Hi Ben, Thanks for your reply, woudn't that insert a string with a value of'NULL';? ""Ben Litton"" <ben.litton@gmail.com> wrote in message news:op.syun6jsq1nzadm@ben.scienceboard.org...-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/Either cast your empty ints (which should make it zero) or do an if (!isset($variable)) { $variable = 'NULL'; } Ben On Tue, 18 Oct 2005 12:15:41 -0400, "Shaun" <shaunthornburgh@hotmail.com> wrote:Hi, Up to this point in time I used to construct my insert statements like this $qid = mysql_query('INSERT INTO MYTABLE (-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/column1, column2, ) VALUES ( "'.$value1.'", "'.$value2.'" )');However I understand it is better to remove the quote marks around an insert if the column type is an integer. This is easy to do, however if the $value is empty it causes a mysql error. Has anyone encountered this and found a solution? Thanks for your advice