php - Simple PDO update is not working -
the problem on :soundid if type manually soundid='soundidfrompost' received post, row updated, soundid=:soundid ... nothing. why?
pdo::attr_errmode pdo::errmode_exception , error_reporting enabled.
public function save($args) { $userid = controller::getuserconnection(); if ($userid) { $soundid = $_post['soundid']; $track_title = $_post['track_title']; $track_artist = $_post['track_artist']; $track_album = $_post['track_album']; $track_genre = $_post['track_genre']; $track_description = $_post['track_description']; $played = 1; $statement = $this->_db->prepare("update sounds set title=:track_title, artist=:track_artist, album=:track_album, genre_id=:track_genre, description=:track_description, played=:played soundid=:soundid , userid=:userid , ip=:ip"); $statement->bindparam(':soundid',$soundid,pdo::param_str); $statement->bindparam(':userid',$userid,pdo::param_int); $statement->bindparam(':track_title',$track_title,pdo::param_str); $statement->bindparam(':track_artist',$track_artist,pdo::param_str); $statement->bindparam(':track_album',$track_album,pdo::param_str); $statement->bindparam(':track_genre',$track_genre,pdo::param_int); $statement->bindparam(':track_description',$track_description,pdo::param_str); $statement->bindparam(':ip',$_server['remote_addr'],pdo::param_str); $statement->bindparam(':played',$played,pdo::param_int); $statement->execute(); echo 'saved!'; } }
i following make cleaner , because don't need bind explicitly (please note didn't use variables):
assign post data want use in query array:
$data = array( 'userid' => $userid, 'sounddid' => $_post['soundid'], 'track_title' => $_post['track_title'], 'track_artist' => $_post['track_title'], 'ip' => $_server['remote_addr'], );
write query:
$sth = $this->_db->prepare(" update sounds set title = :track_title, artist = :track_artist soundid = :soundid , userid = :userid , ip = :ip ");
pass in data array executed:
$result = $sth->execute($data);
Comments
Post a Comment