tags:

views:

22

answers:

1

I have a table where it has two datetimes, one of them is a 'completed' datetime, therefore, if it is NULL then the user has not completed.

I am trying to do an update, to update their mobile number.

How can i do it so it does not update the datetime?

currently if the datetime is null it gets set to the earliest possible time.

here is my query:

mysql_query("UPDATE action_4_members
                SET `mobile` = '{$mobile}', 
                    `additional_txt` = '{$additional}', 
                    `misc_data` = '{$store_id}' 
              WHERE `id` = '{$member_id}'") or die(mysql_error());

here is my table definition:

CREATE TABLE `action_4_members` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `campaign_id` int(11) DEFAULT NULL,
  `mobile` varchar(25) DEFAULT NULL,
  `join_txt` varchar(160) DEFAULT NULL,
  `join_txt_date` datetime DEFAULT NULL,
  `additional_txt` varchar(160) DEFAULT NULL,
  `additional_txt_date` datetime DEFAULT NULL,
  `misc_data` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=687 DEFAULT CHARSET=latin1
+1  A: 

An UPDATE statement will only affect the column(s) you specify (with one caveat):

UPDATE YOUR_TABLE
   SET mobile_number = '123-456-7890'

The caveat is that if you have a DEFAULT ON UPDATE TIMESTAMP constraint set on the datetime column, the datetime column value will update to when the UPDATE statement was run. If you don't want this, you need to correct the DEFAULT constraint on the datetime column.

OMG Ponies
Just added my table definition, does this still apply?
Hailwood
@Hailwood: Appreciated, but without the DEFAULT constraint then someone is triggering the datetime column population. Columns don't populate on their own...
OMG Ponies
could php be doing anything by itself? (i.e pre-processing)
Hailwood
OMG Ponies
odd started working perfectly randomly, will accept this as the answer as it provides a good tip :).
Hailwood