I have this code, everything works except on adding image, image is uploaded thru form and supposed to save/update it on the database.
the problem is it doesnt upload the file on my table . (user_image). images are save on the uploads/profile/image/ directory with no problem.
can you please help me what is wrong in ths code. thank you.
<?php
include_once 'config.php';
if(isset($_POST['btn-upload']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$folder="uploads/profile/image/";
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="update user SET user_image='$file' where username = '$username'";
mysql_query($sql);
?>
<script>
alert('image successfully uploaded');
window.location.href='profile.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='profile.php?fail';
</script>
<?php
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit" name="btn-upload">upload</button>
</form>