简体   繁体   中英

Uploading Image works but doesn't store into Databse

I am trying to upload a image into my database.

The script works fine and shows no error messages. The script successfully uploads to a directory within my server called 'profilepics' however it fails to update the database with the image information, there are no errors and when I echo out the script everything works fine such as session variables, the image name field etc.

Here is my query:

$query = "UPDATE members SET image='$pic' WHERE memberID='" . $_SESSION['user'] . "'";
$result = mysqli_query($connection, $query) or exit ("Error in query: $query. ".mysqli_error());

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))  {   
//Tells you if its all ok  
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";  
}  
else {   //Gives and error if its not  
    echo "Sorry, there was a problem uploading your file.";  
}  

UPDATE is only used when you have an existing row which you want to, update.

So use INSERT INTO , as you're inserting a new row.

Example of an INSERT INTO QUERY using your query:

$query = "INSERT INTO members(`image`) VALUES ('". $pic . "')";

thanks for the help everyone, but I found the issue silly me! the query was perfect in case anyone wanted to know, i was being stupid and didn't realize my session is a username and I was checking to see if it matches my memberID -_________________________-

Thanks again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM