-3
我正在嘗試使用此語句更新數據庫中的頭像..我不知道是什麼錯誤,但沒有任何幫助,我將不勝感激。在php中更新頭像
if(isset($_POST['submit'])){
$adminID = $_SESSION['adminID'];
$type = explode('.', $_FILES['avatar']['name']);
$type = $type[count($type)-1];
$url = 'assests/images/users/'.uniqid(rand()).'.'.$type;
if(in_array($type, array('gif', 'jpg', 'jpeg', 'png', 'JPG', 'GIF', 'JPEG', 'PNG'))) {
if(is_uploaded_file($_FILES['avatar']['tmp_name'])) {
if(move_uploaded_file($_FILES['avatar']['tmp_name'], $url)) {
try {
//insert into database with a prepared statement
$stmt = $db->prepare("UPDATE admin SET avatar = '$url' WHERE adminID = $adminID");
$stmt->execute(array(
));
//else catch the exception and show the error.
} catch(PDOException $e) {
$error[] = $e->getMessage();
}
}
}
}
}
怎麼了?你期待的結果是什麼,你會得到什麼? –
我期待它將$ url插入數據庫 –
是的,但是會發生什麼呢?任何錯誤? –