PHP Classes

UPDATE table fields

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  UPDATE table fields  
Subject:UPDATE table fields
Summary:Condition in order to avoid sone fields
Messages:5
Author:w33bs r3db0y
Date:2010-04-16 17:54:23
Update:2010-04-17 20:23:40
 

  1. UPDATE table fields   Reply   Report abuse  
Picture of w33bs r3db0y 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 !

There are 4 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.