我正在挠头,因为我无法弄清楚我的代码下面有什么问题.. $ avatar_path没有保存到mysql表中..
<?php
$avatar_path = $mysqli->real_escape_string('images/'.$_FILES['avatar']['name']);
//check if the file type is image
if (preg_match("!image!",$_FILES['avatar']['type'])) {
//copy image to images/ folder
if (copy($_FILES['avatar']['tmp_name'], $avatar_path)){
//set session variables to display on welcome page
$_SESSION['username'] = $username;
$_SESSION['avatar'] = $avatar_path;
//insert user data into database
$update_row = $mysqli->query("UPDATE user_data SET avatar='$avatar_path' WHERE user_id='1'") or die($mysqli->error());
}
}
?>
答案 0 :(得分:-1)
你可以尝试一下吗?
$update_row = $mysqli->query("UPDATE user_data SET avatar='$avatar_path' WHERE user_id=1") or die($mysqli->error());
(即抑制id值周围的引号)* 整数不需要引用,并且可能通过使mysql将其作为字符串来搞乱它。