Jump to content

Upload Script with insert to mysql


dropfaith

Recommended Posts

I cant get this working

the form is

http://dropfaithproductions.com/test/add.php

it gets to the echo hr and stops doesnt do anything else or display any errors im new to php so i dont have any idea what could be wrong

<?
include("template/conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
echo "<hr>";

      $imageUploadDir = 'images/';

      if(isset($_POST['upload']))
   
      {  
        $Title=$_POST['Title'];
        $Cat=$_POST['Cat'];
        $Photographer=$_POST['Photographer'];
        $Makeup=$_POST['Makeup'];
        $Hair=$_POST['Hair'];
        $Wardrobe=$_POST['Wardrobe'];  
          $imageName1 = $_FILES['image1']['name'];
          $tmpImageName1 = $_FILES['image1']['tmp_name'];
          $imageName2 = $_FILES['image2']['name'];
          $tmpImageName2 = $_FILES['image2']['tmp_name'];
          $imageName3 = $_FILES['image3']['name'];
          $tmpImageName3 = $_FILES['image3']['tmp_name'];
          $imageName4 = $_FILES['image4']['name'];
          $tmpImageName4 = $_FILES['image4']['tmp_name'];

          // the files will be saved in filePath
   
          $imagePath1 = $imageUploadDir . $imageName1;
          $imagePath2 = $imageUploadDir . $imageName2;  
          $imagePath3 = $imageUploadDir . $imageName3;  
          $imagePath4 = $imageUploadDir . $imageName4; 

          $imageName1 = 'images/'. $imageName1;  
          $imageName2 = 'images/'. $imageName2;  
          $imageName3 = 'images/'. $imageName3;  
          $imageName4 = 'images/'. $imageName4;             
          // move the files to the specified directory
  
          // if the upload directory is not writable or
  
          // something else went wrong $result will be false
  
          if( file_exists($tmpName) ){
  
           move_uploaded_file($tmpName, $filePath);
  
          }
  
          if( file_exists($tmpImageName1) ){
  
           move_uploaded_file($tmpImageName1, $imagePath1);
  
          }
  
          if( file_exists($tmpImageName2) ){
  
           move_uploaded_file($tmpImageName2, $imagePath2);
  
          }
  
          if( file_exists($tmpImageName3) ){
  
           move_uploaded_file($tmpImageName3, $imagePath3);
  
          }
  
          if( file_exists($tmpImageName4) ){
  
           move_uploaded_file($tmpImageName4, $imagePath4);
  
          }
          if(!get_magic_quotes_gpc())
  
          {  
              $fileName  = addslashes($fileName);  
              $filePath  = addslashes($filePath); 
          } 
       $rt=mysql_query("insert into gallery (Title, Cat, Photographer, Makeup, Hair, Wardrobe,  image1, image2, image3, image4, file_name, file_size, file_type, file_path) values('$Title'.'$Cat'.'$ Photographer'.'$Makeup'.'$Hair'.'$Wardrobe'.'$imageName1', '$imageName2', '$imageName3', '$imageName4', '$fileName', '$fileSize', '$fileType', '$filePath')")
or die(mysql_error());  
          mysql_query($query) or die('<hr />Error, query failed : ' . mysql_error(). '<hr />'); 
          echo "<h4>Article uploaded</h4><br />";
      } 
?>

Link to comment
https://forums.phpfreaks.com/topic/122485-upload-script-with-insert-to-mysql/
Share on other sites

so i just moved the connection down and still cant get any errors any ideas on making this work or at least printing the error so i can fiqure it out

<?php
include("template/conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
echo "<hr>";

      $imageUploadDir = 'images/';

      if(isset($_POST['upload']))
   
      {  
        $Title=$_POST['Title'];
        $Cat=$_POST['Cat'];
        $Photographer=$_POST['Photographer'];
        $Makeup=$_POST['Makeup'];
        $Hair=$_POST['Hair'];
        $Wardrobe=$_POST['Wardrobe'];  
          $imageName1 = $_FILES['image1']['name'];
          $tmpImageName1 = $_FILES['image1']['tmp_name'];
          $imageName2 = $_FILES['image2']['name'];
          $tmpImageName2 = $_FILES['image2']['tmp_name'];
          $imageName3 = $_FILES['image3']['name'];
          $tmpImageName3 = $_FILES['image3']['tmp_name'];
          $imageName4 = $_FILES['image4']['name'];
          $tmpImageName4 = $_FILES['image4']['tmp_name'];

          // the files will be saved in filePath
   
          $imagePath1 = $imageUploadDir . $imageName1;
          $imagePath2 = $imageUploadDir . $imageName2;  
          $imagePath3 = $imageUploadDir . $imageName3;  
          $imagePath4 = $imageUploadDir . $imageName4; 

          $imageName1 = 'images/'. $imageName1;  
          $imageName2 = 'images/'. $imageName2;  
          $imageName3 = 'images/'. $imageName3;  
          $imageName4 = 'images/'. $imageName4;             
          // move the files to the specified directory
  
          // if the upload directory is not writable or
  
          // something else went wrong $result will be false
  
          if( file_exists($tmpName) ){
  
           move_uploaded_file($tmpName, $filePath);
  
          }
  
          if( file_exists($tmpImageName1) ){
  
           move_uploaded_file($tmpImageName1, $imagePath1);
  
          }
  
          if( file_exists($tmpImageName2) ){
  
           move_uploaded_file($tmpImageName2, $imagePath2);
  
          }
  
          if( file_exists($tmpImageName3) ){
  
           move_uploaded_file($tmpImageName3, $imagePath3);
  
          }
  
          if( file_exists($tmpImageName4) ){
  
           move_uploaded_file($tmpImageName4, $imagePath4);
  
          }
          if(!get_magic_quotes_gpc())
  
          {  
              $fileName  = addslashes($fileName);  
              $filePath  = addslashes($filePath); 
          } 
       $rt=mysql_query("insert into gallery (Title, Cat, Photographer, Makeup, Hair, Wardrobe,  image1, image2, image3, image4, file_name, file_size, file_type, file_path) values('$Title'.'$Cat'.'$ Photographer'.'$Makeup'.'$Hair'.'$Wardrobe'.'$imageName1', '$imageName2', '$imageName3', '$imageName4', '$fileName', '$fileSize', '$fileType', '$filePath')")
or die(mysql_error());  
          mysql_query($query) or die('<hr />Error, query failed : ' . mysql_error(). '<hr />'); 
          echo "<h4>Article uploaded</h4><br />";
      } 
?>

 

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.