People, please help to make the download avatar in the user table. There is a script, but when loading an image it creates a new user, but it’s necessary that the name of the picture be recorded in the user's column, say, "avatar" or "userimage".

  • Specify, please: 1) what knowledge do you have in php, 2) the source code of the download script would not hurt. - Sh4dow

2 answers 2

In general, the solution looks like this:

Create an avatar field in the user table

After downloading the file and doing all the checks

$userID = 15; // получить ИД пользователя, загрузившего аватар $file = str_replace($_SERVER['DOCUMENT_ROOT'], '/', $uploadedFilePath); // получить путь вида '/img/avatars/15.jpg' mysql_query("UPDATE users SET avatar='$file' WHERE id='$userID';");` 

    By joining the above post, I just want to add that you can find out the id of the newly added record within the current connection with mysql using the request

     SELECT LAST_INSERT_ID(); 

    So you learn user_id.

    • ... or by using the <a href=" php.net/manual/ru/ru/…> function from PHP. - Sh4dow
    • Please tell me how to make it so that the authorized user uploads the picture to his own table. For example, in the example above, it says $ userID = 15. So how can I change what the avatar is loading for the user who is authorized and not for the fifteenth user? $ userID = $ userID, $ userID = $ ID, does not fit. (and everything is exactly the opposite, also does not fit.) Thanks in advance for your responsiveness !!! - webkostya
    • Usually a user table is stored on the server. Suppose there are three columns: user_id, login, password. When authorizing by the entered login (with password verification), you extract user_id from the database. - Retrill