简体   繁体   中英

Having difficulties Uploading Photo in Database through PHP

Need Help: I am using a simple PHP code to upload photos into remote database. But.. Everytime, two copies of one photo is saved int the DB. Can anyone tell me whats I am doing wrong? PHP Code:

<?PHP
$uploadDir = 'image_folder/'; 



$uploadDir = 'image_folder/'; 

if(isset($_POST['Submit']))  //info saving in the variables
{
$fileName = $_FILES['Photo']['name'];
$tmpName  = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath); //moving the photo in the         destination
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
    $filePath = addslashes($filePath);
}
echo "".$filePath."";
$query = "INSERT INTO picture (image) VALUES ('$filePath')";
if (mysql_query($query))
{echo "Inserted";}
mysql_query($query) or die('Error loading file!'); 
}?>
if (mysql_query($query))
{echo "Inserted";}
mysql_query($query) or die('Error loading file!'); 

you are calling mysql_query($query) twice

You are doing mysql_query($query) two times, first in IF{} and right after it. :D

ps. mysql_* functions are depricated, use PDO or mysqli

You are using mysql_query two times. Try this:

if (mysql_query($query)) {
  echo "Inserted";
} else {
 die('Error loading file!'); 
}

You are executing mysql_query twice. Modify your if to:

  if (mysql_query($query)) {
        echo "Inserted";
  } else {
     die('Error loading file!')
  }

And, remove the following line:

 mysql_query($query) or die('Error loading file!'); 

Note: Make sure that you read the warning box in http://in2.php.net/mysql_query . mysql_* functions are deprecated.

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