gpt4 book ai didi

php - 无法让 mysql 查询工作

转载 作者:行者123 更新时间:2023-11-29 13:50:40 25 4
gpt4 key购买 nike

好的,我的网站的函数文件中有这两个函数,它们也在那里将文件名移动到我的数据库以提取图像,这是不起作用的查询

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 似乎不想在一个页面上处理两个图像上传,这很烦人,因为我还需要个人资料上传位和作品集图像,是这样吗?甚至有可能,或者我必须将每个图像上传到单独的页面上:/

最佳答案

我确定你有一个 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 ?

关于php - 无法让 mysql 查询工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16725766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com