Uploading an avatar

People, please help me upload the avatar to the user table. There is a script, but when uploading an image, it creates a new user, but it is necessary that the name of the image is written in the user column, for example, “avatar” or “userimage”.

Answer 1, authority 100%

Joining the above post, I just want to add that you can find out the id of the newly added record within the current mysql connection using a query


This is how you find out the user_id.

Answer 2, authority 50%

In general, the solution looks like this:

Create an “avatar” field in the user table

After uploading the file and doing all the checks, do

$userID = 15; //   ,  
$file = str_replace($_SERVER['DOCUMENT_ROOT'], '/', $uploadedFilePath); //    '/img/avatars/15.jpg'
mysql_query("UPDATE users SET avatar='$file' WHERE id='$userID';");`