This is how the table users looks like:
---------------------------------------------------
| ID | user | avatar |
| 3 | ane22 | /img/default-avatar.png |
| 4 | cuz33 | /img/default-avatar.png |
Upload button:
<form method="POST"
action=""
enctype="multipart/form-data">
<input type="file"
name="uploadfile"
value="" />
<div>
<input type="submit" name="action" value="Upload">
</div>
</form>
This is how I am trying to update the profile picture for the current user:
} else if ($_POST['action'] == 'Upload') {
//action for delete
error_reporting(0);
$msg = "";
$name = $_SESSION["user"];/* user */
// If upload button is clicked ...
if (isset($_POST['upload'])) {
$filename = $_FILES["uploadfile"]["name"];
$tempname = $_FILES["uploadfile"]["tmp_name"];
$folder = "image/".$filename;
// Get all the submitted data from the form
$sql = "UPDATE users SET avatar='" . $filename . "' WHERE user='" . $name . "'";
// Execute query
mysqli_query($link, $sql);
// Now let's move the uploaded image into the folder: image
if (move_uploaded_file($tempname, $folder)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
}
$result = mysqli_query($link, "SELECT * FROM users");
When I press the upload button, nothing happens. And nothing changes in my table also. Any tips?
isset($_POST['upload'])is correct? Have you checked what$_POSTcontains.WHERE user='" . $id . "'are you sure about it?