w33bs r3db0y - 2010-04-16 18:29:05
I am a beginner in PHP programming, but I fallowed up a some tutorials and I understand it a little but I have a problem, I am trying to update some database fields , not all, with the fallowing function:
public function update() {
global $database;
$class_name = get_called_class();
$object = new $class_name;
$attributes = $this->sanitized_attributes();
$attribute_pairs = array();
foreach($attributes as $key => $value) {
$attribute_pairs[] = "{$key}='{$value}'";
}
$sql = "UPDATE ".$object::$table_name." SET ";
$sql .= join(", ", $attribute_pairs);
$sql .= " WHERE id=". $database->escape_value($this->id);
echo $sql;
$database->query($sql);
return ($database->affected_rows() == 1) ? true : false;
}
I get the fallowing message:
UPDATE movies SET id='', name='Alice in Wonderland (2010', poster='', poster_type='', poster_size='', poster_caption='Poster Alice in Wonderland', director='Tim Burton', actors='Mia Wasikowska, Johnny Depp, Helena Bonham Carter', genre='Adventure | Family | Fantasy', plot='19-year-old Alice returns to the magical world from her childhood adventure, where she reunites with her old friends and learns of her true destiny: to end the Red Queen\'s reign of terror.', trailer='http://www.youtube.com/watch?v=DeWsZ2b_pK4', trailer_caption='Trailer Alice in Wonderland' WHERE id=Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
How can I skip updating the id, the poster, poster_type, etc, and update just the ones I have been modified?
Sorry for my grammar, it's not my native language. Thank you !