Jump to content

inserting an image path into the database


svgmx5

Recommended Posts

I've got this script, in which i want to insert the image path into my database. The image is saved into a folder on the server, then the location should be updated into the database. I'm not getting any errors so far, the file is just not getting uploaded into the folder or database.

 

I hope some can give a hand

 

Thank

 

Code is below

 

<?php
if(isset($_POST['update']) && !empty($_POST['update'])){
//Determine the path to which we want to save this file

        $thumbPath = "images/userImages/";

 $thumbPath = $thumbPath . basename($_FILES['profileImage']['name']);
					  
//Attempt to move the uploaded file to it's new place
if(move_uploaded_file($_FILES['profileImage']['tmp_name'], $thumbPath)){
        $sql = "UPDATE tutorProfiles SET img='$thumbPath ' WHERE tutor='$tutorID'";
$run = mysql_query($sql) or die(mysql_error());
	$msg = '
		<p>profile Image updated Succesfully!</p>
	';
}else{
	$msg = '
		<p>There was an error updating your profile image</p>
	';
}
    }
?>

 

I've used this code in the past to insert images into a folder, but to insert the image location into the database.

The reason it's not being inserted/updated in the database, is because if inside an IF and the condition is returning false.

 

   if(move_uploaded_file($_FILES['profileImage']['tmp_name'], $thumbPath)){

 

the image isn't being moved, so the query inside this if block won't execute.

 

So what you have to do is figure out why the image isn't being moved.

 

Most likely folder permission issues.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.