好的我在我的网站的函数文件中有这两个函数,他们也在那里将文件名移动到我的数据库中以提取图像这是查询无法正常工作
function change_profile_image($user_id, $file_temp, $file_extn){
$file_path = 'images/profile/' .substr(md5(time()), 0, 10). '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
mysql_query ("UPDATE `users` SET `profile` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id);
}
function portfolio_image($user_id, $file_temps, $file_extns ){
$file_paths = 'images/portfolio/' .substr(md5(time()), 0, 9). '.' . $file_extns;
move_uploaded_file($file_temps, $file_paths);
mysql_query ("UPDATE `users` SET `image` = '" . mysql_real_escape_string ($file_paths) . "' WHERE `user_id` = " . (int)$user_id);
}
表格
<textarea name="last_name" placeholder="surname" class="name"><?php echo $user_data['last_name'] ?></textarea> <br>
<input class="proupload" type="file" name="profile"><input class="profilepicup" type="submit" value="Upload">
<? if (isset($_FILES['profile']) === true){
if (empty($_FILES['profile']['name'])=== true){
echo "<p> please choose a file </p>";
} else {
$allowed = array('jpg','jpeg','gif','png');
$file_name = $_FILES['profile']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['profile']['tmp_name'];
if (in_array($file_extn, $allowed) === true) {
change_profile_image($session_user_id, $file_temp, $file_extn );
} else {
echo '<p>Incorrect file type.</p>';
}
}
}
?>
<form action= "portfolioupload.php" method ="post" enctype="multipart/form-data">
<input class="proupload" type="file" name="profile"><input class="profilepicup" type="submit" value="Upload">
</form>
<?php if (isset($_FILES['profile']) === true){
if (empty($_FILES['profile']['name'])=== true){
echo "<p> please choose a file </p>";
} else {
$allowed = array('jpg','jpeg','gif','png');
$file_name = $_FILES['profile']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['profile']['tmp_name'];
if (in_array($file_extn, $allowed) === true) {
portfolio_image($session_user_id, $file_temp, $file_extn );
} else {
echo '<p>Incorrect file type.</p>';
}
}
}
?>
我把这些查询放在不同的页面上并且它们工作php和mysql似乎不想在一个页面上使用两个图像上传这很烦人,因为我需要一个配置文件上传位和投资组合图像,这是甚至可能,或者我必须将每个图像上传到不同的页面上:/
答案 0 :(得分:1)
我确定你有一个var $ file_path ..
mysql_query ("UPDATE `users` SET `portfolios` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id);
或许你有$ file_path和$ file_paths?
答案 1 :(得分:0)
只需使用or die(mysql_error())
进行简单的错误处理即可完成。
mysql_query ("UPDATE `users` SET `profile` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id))or die(mysql_error());
修改强>
好的,只需打开普通的php文件,连接到db并运行此查询
mysql_query ("UPDATE `users` SET `profile` = 'test' WHERE `user_id` = '1')or die(mysql_error());
并检查您的数据库是否已更新,如果没有,您将收到可读错误。