Writing MySQL Update Query with NULL value

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

 



I'm trying to write a MySQL UPDATE query where one or more variables may be NULL. So, I'm trying something like:

  $last_name = $_POST['last_name'];
  $first_name = $_POST['first_name'];
  $suffix = $_POST['suffix'];
  $suffix = empty($suffix) ? NULL : $suffix;
  $phone = $_POST['phone'];
  $phone_index = $_POST['phone_index'];
  $update_query = "UPDATE 'phones'
                   SET 'last_name' = $last_name, 'first_name' = $first_name,
                   'suffix' = $suffix, 'phone' = $phone
                   WHERE 'phone_index' = $phone_index;";

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;

I think, for this to properly update the record, it should be:
UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = NULL, 'phone' = 123-456-7890 WHERE 'phone_index' = 323;

What am I doing wrong?

     -----===== Bill =====-----
--

Nothing is so bad that it can't get worse.



--
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