Php file path / file extension not stored in database in sql

I successfully scramble and upload images to my database, but the file path is not saved on the Profile tab in my sql database. What is wrong here? How to fix it.

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 'yu 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 'yu no jpg or png or gif'; } } } if (empty($user_data['profile']) === false) { echo '<img src"', $user_data['profile'], '" alt="">'; } ?> 
+4
source share
1 answer

Your line of code:

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

Take a look

 `profile` = " . $file_path . "' 

You forgot "at the beginning of $file_path ;)

+1
source

Source: https://habr.com/ru/post/1446743/


All Articles