droidus Posted August 28, 2011 Share Posted August 28, 2011 i have a form that edits a user in the database. here is what i have right now: if (isset($_POST['submit'])) { mysql_select_db($database_uploader, $uploader); $query = "SELECT * FROM members WHERE id='" . mysql_real_escape_string($id) . "'"; if (mysql_num_rows($result) > 0) { $name = $row[name]; $username = $row[uname]; $email = $row[email]; $acntActivation = $row[activated]; $accountType = $row[acntType]; $accountStatus = $row[acntStatus]; $bandwhitech = $row[bandwhitech]; $notes = $row[notes]; $timezone = $row[timezone]; // METHOD: If $_post[name] != $name, then update database record to new value mysql_query(sprintf("UPDATE members SET notes = '%s'", mysql_real_escape_string("hello there!"))) or die(mysql_error()); mysql_close($con); } } 1) the notes are not being updated 2) what would be the best way to update each field that is changed. i was just going to insert each individually, after checking if it is different than what is in the database for the record. would it just be better to update the whole record, instead of one piece at a time? it seems like the first way would take up too much load time. Quote Link to comment https://forums.phpfreaks.com/topic/245853-efficent-method-of-updating-database/ Share on other sites More sharing options...
Psycho Posted August 28, 2011 Share Posted August 28, 2011 would it just be better to update the whole record, instead of one piece at a time? Yes. No need to check which fields have changed. Just do an UPDATE with all the fields that are on the form that you allow to change. Quote Link to comment https://forums.phpfreaks.com/topic/245853-efficent-method-of-updating-database/#findComment-1262734 Share on other sites More sharing options...
jcbones Posted August 28, 2011 Share Posted August 28, 2011 To better clarify, MySQL is smart, and it will only update columns that CHANGE. If you set a column to the value it currently has, MySQL notices this and does not update it. Quote Link to comment https://forums.phpfreaks.com/topic/245853-efficent-method-of-updating-database/#findComment-1262880 Share on other sites More sharing options...
droidus Posted August 28, 2011 Author Share Posted August 28, 2011 ok, thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/245853-efficent-method-of-updating-database/#findComment-1262915 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.