Jump to content

efficent method of updating database


droidus

Recommended Posts

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. :P

Link to comment
https://forums.phpfreaks.com/topic/245853-efficent-method-of-updating-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.