简体   繁体   English

无法获得MySQL查询工作

[英]Cant get mysql query working

ok I have these two functions in my functions file for my site they are there too move files names to my database to pull in images this is the query thats not working 好的,我在我的站点的函数文件中有这两个函数,它们在那里也将文件名移到数据库中以提取图像,这是查询无效

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);

}

the forms 表格

<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>';

            }
            }
     }


?>

I've put these queries on separate pages and they work php and mysql seems not not want to work with two image uploads on one page which is annoying as i need an profile upload bit and a portfolio image as well, is this even possible or am i going to have to have each image upload on separate pages :/ 我将这些查询放在单独的页面上,它们可以工作php和mysql,似乎不希望在一页上使用两个图像上传,这很烦人,因为我还需要一个配置文件上传位和一个图片集图像,这甚至可能还是我是否需要将每个图像上传到单独的页面上:/

I'm sure that you have one var $file_path .. 我确定您有一个var $ file_path ..

mysql_query ("UPDATE `users` SET `portfolios` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id);

Or maybe you have $file_path and $file_paths ? 或者,也许您有$ file_path和$ file_paths?

Just do simple error handling with or die(mysql_error()) and be done with it. 只需使用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());

EDIT 编辑

Ok, just open plain php file, connect to db and just run this query 好的,只需打开简单的php文件,连接到数据库并运行此查询即可

 mysql_query ("UPDATE `users` SET `profile` = 'test' WHERE `user_id` = '1')or die(mysql_error());

And check if your db is updated, if not, you WILL get a readable error. 并检查您的数据库是否已更新,否则,您将得到一个可读错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM