php - 无法让 mysql 查询工作

标签 php mysql photo

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

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/

相关文章:

php - 在作为 Assets 包含的 javascript 文件中使用 Laravel 函数

mysql - Eclipse JPA (MySQL) 自动生成位字段到字节,我可以让它生成位到 bool 值吗

ios - 如何从 iPhone 获取除相机胶卷之外的所有资源?

R/ImageJ : Measuring shortest distance between points and curves

ios - 如何获取每个地理位置的照片?

php - Cakephp 查找条件的空安全运算符

php - 如何使用 php 从另一个主机服务器检索 http 页面并检测重定向

php - 无法从复选框中获取值并用于另一个 php 文件

mysql - mysql 的 jdbc url 不适用于 IP 地址

php - 如何创建对特定列的搜索?