Re: Writing MySQL Update Query with NULL value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Apr 13, 2008 at 10:24 PM, Bill Guion <bguion@xxxxxxxxxxx> wrote:
>
>  However, when I echo out this query, I get:
>  UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = ,
> 'phone' = 123-456-7890 WHERE 'phone_index' = 323;

    Bill,

    You're missing quotes around your data, and using quotes on field
names.  Instead, try structuring your query so that it will output
like this, with quotes around data, and backticks around table and
field names.:

UPDATE `phones` SET `last_name` = 'Doe', `first_name` = 'John',
`suffix` = '', `phone` = '123-456-7890' WHERE `phone_index` = '323'

    NOTES:
        * See the missing semicolon at the end?  It's because you
shouldn't use the semicolon in PHP's mysql_*() functions.
[http://php.net/mysql_query]
        * You may also want to force a LIMIT 1 to the end of that
query.  I'm sure `phone_index` is a unique AUTO_INCREMENT, but I still
prefer to tack it on just to ensure that MySQL knows we're only
messing with one thing.  It's also an added layer of security in case
(God forbid) anything goes wrong.

-- 
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux