0
問題是:soundid,如果我手動鍵入soundid ='soundidfromPOST'從POST接收,行更新,但與soundid =:soundid ...什麼都沒有。爲什麼?簡單的PDO更新不起作用
PDO :: ATTR_ERRMODE到PDO :: ERRMODE_EXCEPTION和error_reporting啓用。
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 WHERE soundid=:soundid AND userid=:userid AND 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!';
}
}
是不是一個數字?你將它綁定爲一個字符串。您還可以查看var_dump($ statement-> ErrorInfo())和var_dump($ this - > _ db-> ErrorInfo())'來查看數據庫中的錯誤。 – andrewsi
功能之外不是數組數組嗎?嘗試通過後變量作爲參數? –
@RoyalBg - $ _POST作爲全局自動提供。 – andrewsi