путь к файлу php/расширение файла не сохраняется в базе данных в sql


Я успешно скремблирую и загружаю изображения в свою базу данных, однако путь к файлу не сохраняется на вкладке "профиль" в моей базе данных sql. Что здесь не так? Как мне это исправить?

include 'core/init.php';

function change_profile_image($user_id, $file_temp, $file_extn) {
$file_path = 'profile/' . substr (md5(time()), 0, 10) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
mysql_query("UPDATE `users` SET `profile` = " . $file_path . "' WHERE `user_id` = " . (int)$user_id);

}

 if (isset($_FILES['profile']) === true) {
    if (empty($_FILES['profile']['name']) === true) {
       echo 'y u no choose file!';
  } 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);

        header('Location: dontdelete.php');
        exit();

       }else {
        echo 'y u no jpg or png or gif';       

       }
  }
 }

if (empty($user_data['profile']) === false) {
    echo '<img src"', $user_data['profile'], '" alt="">'; 
}


?>
Author: thedullmistro, 2012-11-18

1 answers

Ваша строка кода:

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

Посмотрите на

`profile` = " . $file_path . "'

Вы забыли 'в начале $file_path ;)

 1
Author: Sietse, 2012-11-18 10:44:38