I doesn't found answer on stackoverflow that works for me, so when I save data to mySQL using PHP, I added 2 parameters. When saving imgfile parameter, it just saves parameter name.
Parameter:
$stmt->bindParam(':imgfile', $newfilename);
In Database after updating:
---------------------------
ID imgfile
---------------------------
1 :imgfile
---------------------------
What expected to see:
---------------------------
ID imgfile
---------------------------
1 45678_profile.png
---------------------------
My whole code(I set id to 1, the user that exists, if PHP was not able to get ID):
if (move_uploaded_file($_FILES["file"]["tmp_name"], "/home1/bubos/public_html/homework/images/pfimages/" . $newfilename)) {
$stmt = $conn->prepare("UPDATE `users` SET `profileimg` = ':imgfile' WHERE `users`.`id` = 1");
$stmt->bindParam(':id', $_SESSION['user_id']);
$stmt->bindParam(':imgfile', $newfilename );
if ( $stmt = $conn->prepare("UPDATE `users` SET `profileimg` = ':imgfile' WHERE `users`.`id` = 1")) {
$stmt->execute();
$message = "Image was uploaded to server and set successfully!";
} else {
$message = "Image uploaded to server, but error occurred on image setting!";
}
} else {
$message = "Error on image uploading to server!";
}
Can anyone say how can I fix it?