fubowl Posted October 17, 2010 Share Posted October 17, 2010 public function update($data, $table, $where) { foreach ($data as $column => $value) { $sql = "UPDATE $table SET $column = $value WHERE $where"; print "table: ".$table." column: ".$column." where: ".$where; mysql_query($sql) or die(mysql_error()); } return true; } $data: $data = array( "username" => "Jack", "email" => "[email protected]" ); $db->update($data, "users", 'id=1'); Working on this code that updates a column from a class. Everything is fine except for one issue. As of right now $column is set to "Jack" which outputs an error, instead of what it should be as "username". I'm sure it's something really simple, so any assistance is appreciated. Any ideas? Problem area is listed in red. Link to comment https://forums.phpfreaks.com/topic/216060-foreach-help/ Share on other sites More sharing options...
fubowl Posted October 17, 2010 Author Share Posted October 17, 2010 Whoops, that wasn't the issue. $sql should have = $sql = "UPDATE $table SET $column='$value' WHERE $where"; Link to comment https://forums.phpfreaks.com/topic/216060-foreach-help/#findComment-1122904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.