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

Reply via email to