Re: Writing MySQL Update Query with NULL value
| From: | Daniel Brown | Date: | Mon, 14 Apr 2008 14:18:43 +0000 |
| Subject: | Re: Writing MySQL Update Query with NULL value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272973@lists.php.net to get a copy of this message | ||
On Sun, Apr 13, 2008 at 10:24 PM, Bill Guion <bguion@comcast.net> 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!