JustinK101 Posted December 6, 2005 Share Posted December 6, 2005 Hello, I have a form that has a series of checkboxes. I store if the checkbox is checked and what time it was checked. The problem is when I update one or two checkboxes and submit it changes all the dates in the database. It updates all the dates because I am using the mysql UPDATE function, and since the date is different from what is stored previously it just overides the date, even though I didnt acutally change a checkbox state necessary. Perhaps some code would help. $_1_date = date('Y-m-d G:i:s', time() - $time_offset); $_2_date = date('Y-m-d G:i:s', time() - $time_offset); $_3_date = date('Y-m-d G:i:s', time() - $time_offset); // UPDATE EXISTING CHECKLIST if(isDuplicate("checklist" , "associated_order_id" , $order_id)) { $sql = "UPDATE checklist SET _1 = '$_1', _1_date = '$_1_date', _2 = '$_2', _2_date = '$_2_date' , _3 = '$_3', _3_date = '$_3_date' WHERE `associated_order_id` = '" . $order_id . "' LIMIT 1"; mysql_query($sql) || die(mysql_error()); echo '<p align="center" class="success">Checklist updated <b>successfully</b>! </p>'; die(); } // CREATE NEW CHECKLIST else { $sql = "INSERT INTO checklist ( associated_order_id, _1, _1_date, _2, _2_date, _3, _3_date ) VALUES ( '$order_id', '$_1', '$_1_date', '$_2', '$_2_date', '$_3', '$_3_date' )"; mysql_query($sql) || die(mysql_error()); echo '<p align="center" class="success">Checklist created <b>successfully</b</p>'; die(); } So _1, _2, _3 store the value of the check boxes and _1_date, _2_date, _3_date store the current date. Quote Link to comment https://forums.phpfreaks.com/topic/2990-mysql-update-call-with-dates/ Share on other sites More sharing options...
fenway Posted December 24, 2005 Share Posted December 24, 2005 That's because you're not checking the initial state of the checkboxes you set -- you're always updated all of the checkboxes! You need to only include those checkboxes whose values have changed. Since you know what they were when you populated the page (i.e. in hidden values or query the DB again), you can check against those first, and build your UPDATE clause accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/2990-mysql-update-call-with-dates/#findComment-10378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.